CodeForces - 416A (判断大于小于等于 模拟题)
Time Limit: 1000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
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
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
17
2
> 100 Y
< -100 Y
Impossible
Source
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int f[]; int main()
{
int n,min0=-,max0=;
cin>>n;
for(int i=;i<n;i++)
{
char x[],an;int num;
cin>>x>>num>>an;
if(an=='Y'&&x[]=='>')
{
if(x[]=='=')
min0=max(min0,num);
else min0=max(min0,num+);
}
else if(an=='N'&&x[]=='>')
{
if(x[]=='=')
max0=min(max0,num-);
else max0=min(max0,num);
}
else if(an=='Y'&&x[]=='<')
{
if(x[]=='=')
max0=min(max0,num);
else max0=min(max0,num-);
}
else if(an=='N'&&x[]=='<')
{
if(x[]=='=')
min0=max(min0,num+);
else min0=max(min0,num);
}
// cout<<max0<<' '<<min0<<endl;
}
if(max0>=min0)
cout<<min0<<endl;
else cout<<"Impossible"<<endl;
return ;
}
CodeForces - 416A (判断大于小于等于 模拟题)的更多相关文章
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Codeforces Beta Round #3 C. Tic-tac-toe 模拟题
C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone i ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Beta Round #7 B. Memory Manager 模拟题
B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- CSP复赛day2模拟题
没错,我又爆零了.....先让我自闭一分钟.....so 当你忘记努力的时候,现实会用一记响亮的耳光告诉你东西南北在哪. 好了,现在重归正题: 全国信息学奥林匹克联赛(NOIP2014) 复赛模拟题 ...
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
随机推荐
- 宿主机( win 7 系统) ping 虚拟机VMware( cent os 6.6 ) 出现“请求超时”或者“无法访问目标主机”的解决方法
首先虚拟机的网络连接设置为"Host-only": 然后在 cmd 窗口中查看 VMnet1 的 ip 地址,这里是 192.168.254.1 接下来在 Linux 中设置网卡地 ...
- POJ2186 Popular Cows
Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...
- [NOIP2009] 普及组
多项式输出 模拟 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> # ...
- BZOJ 3224 TYVJ 1728 普通平衡树 [Treap树模板]
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 7390 Solved: 3122 [Submit][S ...
- ASP.NET MVC4中调用WEB API的四个方法
http://tech.it168.com/a2012/0606/1357/000001357231_all.shtml [IT168技术]当今的软件开发中,设计软件的服务并将其通过网络对外发布,让各 ...
- Spring学习1-初识Spring
一.简介 1.Spring是一个开源的控制反转(Inversion of Control ,IoC)和面向切面(AOP)的容器框架.它的主要目得是简化企业开发. 2.为何要使用Spring? ...
- PHP输出表格的方法
<?php function table($n) //几行几列表 { echo'<table border="1" width="500" heig ...
- 大理石在哪?(Where is the Marble?,UVa 10474)
参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...
- pthread clean up
https://www.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part4/ http://www.cnblogs.com/xfi ...
- Linux samba配置
更详细的配置地址:http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html 1 安装 yum -y install samba 2 ...