Codeforces Round #241 (Div. 2)->A. Guess a number!
1 second
256 megabytes
standard input
standard output
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".
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.
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).
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
17
2
> 100 Y
< -100 Y
Impossible
题意理解:猜数字,输出猜出的数字中任意一个,如果不符合则输出“Impossible”。
#include<bits/stdc++.h>
using namespace std;
const int INF=;
int main()
{
int n,x;
cin>>n;
int high=INF,low=-INF;//取临界值
for(int i=; i<n; i++)
{
char s[]= {},t[];
scanf("%s%d%s",s,&x,t);
if(t[]=='N')
{
s[]^='=';
s[]^='<'^'>';
}//如果是N的话则把它取反
if(s==string(">")) low=max(low,x+);//前面用char后面得强制转换一下
if(s==string("<")) high=min(high,x-);
if(s==string(">=")) low=max(low,x);
if(s==string("<=")) high=min(high,x);
}//大取大小取小
if(low<=high) printf("%d\n",low);
else printf("Impossible\n");
return ;
}
Codeforces Round #241 (Div. 2)->A. Guess a number!的更多相关文章
- DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...
- Codeforces Round #241 (Div. 2)->B. Art Union
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #241 (Div. 2) B. Art Union 基础dp
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #241 (Div. 2) B dp
B. Art Union time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #241 (Div. 2) B. Art Union (DP)
题意:有\(n\)个画家,\(m\)幅画,每个画家负责\(m\)幅画,只有前一个画家画完时,后面一个画家才能接着画,一个画家画完某幅画的任务后,可以开始画下一幅画的任务,问每幅画最后一个任务完成时的时 ...
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数学 质因数个数
D. Soldier and Number Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #265 (Div. 1) C. Substitutes in Number dp
题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...
随机推荐
- SQLSERVER中按年月分组
SQLSERVER中按年月分组 一个表有三个字段id,dt,d 分别存放id,时间,数值 id dt d 1 2004-08-11 12:12:00.000 9 2 2005-09- ...
- iOS-设置启动图片
启动图片设置 设置方法一 这种方法里,默认模拟器和真机的尺寸和启动图片的尺寸相同. 通过美工提供各种尺寸的启动图片来适配屏幕的大小.这种方法要求美工提供各种屏幕大小的图片. 步骤如下: 1.如图所示, ...
- GDAL读取tiff文件/C++源码
// gdal_geotiff.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "gdal_priv.h&quo ...
- codevs 3185 队列练习1
题目描述 Description 给定一个队列(初始为空),只有两种操作入队和出队,现给出这些操作请输出最终的队头元素. 操作解释:1表示入队,2表示出队 输入描述 Input Description ...
- Standford CoreNLP
Stanford CoreNLP Stanford CoreNLP提供一组自然语言处理的工具.这些工具可以把原始英语文本作为输入,输出词的基本形式,词的词性标记,判断词是否是公司名.人名等,规格化日期 ...
- 关于MD5加密的小知识
- (NSString *)MD5Hash { const char *cStr = [self UTF8String]; unsigned char result[16]; CC_MD5(cStr, ...
- CAD格式DWF嵌入到自己的网页中展示--Autodesk Design Review
网页上嵌入CAD图纸,用的 Autodesk Design Review控件嵌入IE, 网上的 dwf viewer方式没成功. Head之间 <script type="text/j ...
- IE6和IE7的line-height和现代浏览器不一致的问题
1.我们发现在网页中设置line-height后,现代浏览器显示正常,可是在IE6 IE7下却不能正确解析,这时需要再额外的为旧版浏览器声明: p{ line-height: 30px; *line- ...
- WPF 使用定时器
WPF 使用定时器:<ProgressBar Height="10" HorizontalAlignment="Left" Margin="28 ...
- ActiveMQ之TemporaryQueue和TemporaryTopic
TemporaryQueue和TemporaryTopic,从字面上就可以看出它们是“临时”的目的地.可以通过Session来创建,例如: TemporaryQueue replyQueue = se ...