CodeForces - 416A (判断大于小于等于 模拟题)

Guess a number!

Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.

The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:

  • Is it true that y is strictly larger than number x?
  • Is it true that y is strictly smaller than number x?
  • Is it true that y is larger than or equal to number x?
  • Is it true that y is smaller than or equal to number x?

On each question the host answers truthfully, "yes" or "no".

Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn‘t such value, print "Impossible".

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:

  • ">" (for the first type queries),
  • "<" (for the second type queries),
  • ">=" (for the third type queries),
  • "<=" (for the fourth type queries).

All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").

Consequtive elements in lines are separated by a single space.

Output

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn‘t exist, print word "Impossible" (without the quotes).

Sample Input

Input

4>= 1 Y< 3 N<= -3 N> 55 N

Output

17

Input

2> 100 Y< -100 Y

Output

Impossible

Source

Codeforces Round #241 (Div. 2)

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int f[100005];  

int main()
{
    int n,min0=-1000001000,max0=1000010000;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        char x[3],an;int num;
        cin>>x>>num>>an;
        if(an==‘Y‘&&x[0]==‘>‘)
        {
            if(x[1]==‘=‘)
            min0=max(min0,num);
            else min0=max(min0,num+1);
        }
        else if(an==‘N‘&&x[0]==‘>‘)
        {
            if(x[1]==‘=‘)
                max0=min(max0,num-1);
            else max0=min(max0,num);
        }
        else if(an==‘Y‘&&x[0]==‘<‘)
        {
            if(x[1]==‘=‘)
            max0=min(max0,num);
            else max0=min(max0,num-1);
        }
        else if(an==‘N‘&&x[0]==‘<‘)
        {
            if(x[1]==‘=‘)
                min0=max(min0,num+1);
            else min0=max(min0,num);
        }
       // cout<<max0<<‘ ‘<<min0<<endl;
    }
    if(max0>=min0)
        cout<<min0<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}
时间: 2024-10-12 21:55:25

CodeForces - 416A (判断大于小于等于 模拟题)的相关文章

decode 函数判断大于小于等于的情况

decode函数可以对查询的结果进行替换,decode 实际上的功能和if语句类似. decode(var,var1,value1,var2,value2,var3,value3) 等价于 if var=var1 then ...else if var=var2 then ...else var=var3 then ... 但是仅限于等于情况,如果是判断大于小于的情况,比如if a>b这种情况,仅仅使用decode是无法实现的,需要加入sign()函数. sign函数的功能很简单,sign(va

CodeForces 112D Petya and Divisors 模拟题(水

题目链接:点击打开链接 论科学暴力的姿势重要性.. #include <cstdio> #include <iostream> #include <string.h> #include <math.h> #include <map> #include <algorithm> #include <set> #include <queue> using namespace std; #define ll int #

CodeForces - 427B (模拟题)

Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of t

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

xjoi2016模拟题1

星期天下午被某个sb叫去做xjoi模拟题. 发现自己好弱.STL不熟. T1 一开始是想把每一列的最大平均值算出来,然后每一列相加在算平均值,然后发现这是错误的想法,于是华丽丽的10分. 正解:二分枚举最大平均值,判断是否合法. #include<cstdio>#include<cstdlib>#include<cstring>#define max(x,y) (x>y?x:y)const int N=9001000;long long sum[N];int n,

华为网络技术大赛模拟题答案详解

华为网络技术大赛模拟题答案详解 [尊重原创,转载请注明出处]http://blog.csdn.net/guyuealian/article/details/51354514 一.判断题 (1)VLSM的作用是:在有类的IP地址基础上,从主机位部分划分出相应的位数做为网络位.但是在路由器上部署时,需要路由协议的支持. [解释]对,VLSM=Variable Length Subnet Mask,可变长子网掩码 (2)有效的沟通是任何组织和任何项目的基础,项目经理可以花90%或者更多的时间在沟通这方

阿里云云计算认证ACP模拟考试练习题第6套模拟题分享(共10套)

阿里云认证考试包含ACA.ACP.ACE三种认证类型,报名考试最多的是ACP认证考试,本人整理了100道全真阿里云ACP认证考试模拟试题,适合需要参加阿里云ACP认证考试的人复习,模拟练习.此为第6套模拟题分享. 阿里云云计算认证ACP模拟考试练习题6 认证级别 云计算 大数据 云安全 中间件 助理工程师(ACA) 云计算助理工程师认证报名入口 大数据助理工程师认证报名入口 云安全助理工程师认证报名入口 专业工程师(ACP) 云计算工程师认证报名入口 大数据工程师认证报名入口 大数据分析师认证报

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as