CodeForces 416 A.Guess a number!(水~)

Description

一个人猜数字 y y ,给出四种问题及其结果,即y是否大于、小于、小于等于、大于等于 x x ,回答Y表示是, N N 表示不是,问是否有满足所有条件的y

Input

第一行一整数 n n 表示问答次数,之后输入n个问答 (1n104,109x109) ( 1 ≤ n ≤ 10 4 , − 10 9 ≤ x ≤ 10 9 )

Output

如果存在满足条件的 y y 则输出任一解,否则输出Impossible

Sample Input

4

= 1 Y
3 N
= -3 N
55 N

Sample Output

17

Solution

简单题,根据限制求出 y y 的下限和上限,如果y的取值范围非空则有解,否则无解

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 11
char a[maxn],b[maxn];
int n,c,Min,Max;
int main()
{
    while(~scanf("%d",&n))
    {
        Min=-2000000000,Max=2000000000;
        while(n--)
        {
            a[1]='#';
            scanf("%s%d%s",a,&c,b);
            if(b[0]=='N')
            {
                if(a[0]=='>'&&a[1]=='=')a[0]='<',a[1]='#';
                else if(a[0]=='<'&&a[1]=='=')a[0]='>',a[1]='#';
                else if(a[0]=='>'&&a[1]!='=')a[0]='<',a[1]='=';
                else if(a[0]=='<'&&a[1]!='=')a[0]='>',a[1]='=';
            }
        //  printf("%c%c\n",a[0],a[1]);
            if(a[0]=='>')
            {
                if(a[1]=='=')Min=max(Min,c);
                else Min=max(Min,c+1);
            }
            else 
            {
                if(a[1]=='=')Max=min(Max,c);
                else Max=min(Max,c-1);
            }
        }
        if(Max>=Min)printf("%d\n",Min);
        else printf("Impossible\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值