题意
给出一些类似不等式的东西,求满足条件的最小x。
思路
用两个东西标记范围的大小,如果x>=m,那么l=m,如果x<=某一个数,那么r=m,以此类推,输出就判断l是否小于r然后输出就好了。
代码
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int n,x,r1,r2;
char ans;
string s;
int main()
{
scanf("%d",&n);
r2=10000;r1=-10000;//因为给出的范围是-10000<=x<=10000
for (int i=1;i<=n;i++)
{
cin>>s>>x>>ans;
if (s==">=")//以下是判断各种情况
{
if (ans=='Y') r1=max(r1,x);
else r2=min(r2,x-1);//改变范围
}
else
if (s==">")
{
if (ans=='Y') r1=max(x+1,r1);
else r2=min(r2,x);
}
else
if (s=="<=")
{
if (ans=='Y') r2=min(r2,x);
else r1=max(r1,x+1);
}
else
if (s=="<")
{
if (ans=='Y') r2=min(r2,x-1);
else r1=max(r1,x);
}
}
if (r1<=r2) printf("%d",r1);
else printf("Impossible");
}
214

被折叠的 条评论
为什么被折叠?



