社区讨论
求条P6123
学术版参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mhj0rcxx
- 此快照首次捕获于
- 2025/11/03 18:50 4 个月前
- 此快照最后确认于
- 2025/11/03 18:50 4 个月前
https://www.luogu.com.cn/problem/P6123
CPP#include<bits/stdc++.h>
using namespace std;
struct node
{
int l,r;
}opt[1010];
int top=0;
bool cmp(node a,node b)
{
return a.l<b.l;
}
int main()
{
string s;
while(getline(cin,s))
{
int sy=s.find("&&"),ss=s.size();
if(sy==-1)
{
if(s[2]=='>')s=s+"&& x <= 32767";
else s="x >= -32768 && "+s;
}
sy=s.find("&&");
ss=s.size();
int a=0,b=0;
for(int i=0;i<ss;i++)
{
if(s[i]>='0'&&s[i]<='9')
{
if(i<sy)a=a*10+s[i]-'0';
else b=b*10+s[i]-'0';
}
}
if(s[5]=='-')a=-a;
if(s[sy+8]=='-')b=-b;
opt[++top].l=a;
opt[top].r=b;
}
int flag=0;
sort(opt+1,opt+top+1,cmp);
int l=opt[1].l,r=opt[1].r;
for(int i=2;i<=top;i++)
{
if(r+1>=opt[i].l)r=max(r,opt[i].r);
else
{
if(r==32767&&l==-32768)
{
cout<<"true";
return 0;
}
else if(r==32767)
{
cout<<"x >= "<<l<<" ||"<<endl;
flag=1;
}
else if(l==-32768)
{
cout<<"x <= "<<r<<" ||"<<endl;
flag=1;
}
else if(l<=r)
{
cout<<"x >= "<<l<<" && x <= "<<r<<" ||"<<endl;
flag=1;
}
l=opt[i].l;
r=opt[i].r;
}
}
if(r==32767&&l==-32768)cout<<"true";
else if(r==32767)cout<<"x >= "<<l;
else if(l==-32768)cout<<"x <= "<<r;
else if(l<=r)cout<<"x >= "<<l<<" && x <= "<<r;
else if(flag==0)cout<<"false";
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...