An Easy Task(简箪题)
B. An Easy Task
+
-
You are given an easy task by your supervisor -- to find the best value of X, one of the parameters in an evaluation function, in order to improve the accuracy of the whole program.
However, after a few days' analysis, you realize that it is far harder than you imagine. There are so many values X can be, and the only way to find the best one among them is to try all these possible values one after another!
Fortunately, you know that X is an integer and thanks to the previous works by your senior fellow apprentices, you have got n constraints on X. Each constraint must be in one of the following forms:
1. < k: means that X is less than integer k;
2. > k: means that X is greater than integer k;
3. <= k: means that X is less than or equal to integer k;
4. >= k: means that X is greater than or equal to integer k;
5. = k: means that X is equal to integer k.
Now, you are going to figure out how many possible values X can be, so that you can estimate whether it is possible to finish your task before deadline.
Input
For each test case:
The first line contains an integer n. 0 ≤ n ≤ 10 000.
Then follows n lines, each line contains a comparison operator o and an integer k, separated by a single space. o can be one of “>”, “<”, “>=”, “<=”, and “=”. 0 ≤ | k | ≤ 1 000 000 000.
There is no contradictory between these constraints, in other word, at least one integer value meets all of them.
Output
Sample Input
1
2
> 2
<= 5
Sample Output
3
#include<stdio.h>
#define ll long long
#define inf 9999999999
int main()
{
ll t,n,a,l,r;
char s[5];
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
l=-inf; r=inf;
int flag=1;
while(n--)
{
scanf("%s%lld",s,&a);
if(s[1]!='\0'&&flag)
{
if(s[0]=='>')if(l<a)l=a;
if(s[0]=='<'&&r>a)r=a;
}
else if(flag)
{
if(s[0]=='>'&&l<a+1)l=a+1;
if(s[0]=='<'&&r>a-1)r=a-1;
if(s[0]=='=')
if(l<=a&&a<=r)l=r=a;else flag=0;
}
}
if(flag==0||l>r)printf("0\n");
else if(l==-inf||r==inf)printf("-1\n");
else printf("%lld\n",r-l+1); }
}
An Easy Task(简箪题)的更多相关文章
- HDU-1076-An Easy Task(Debian下水题測试.....)
An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- CodeForces462 A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...
- An Easy Task
An Easy Task Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU-------An Easy Task
An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- ZOJ 2969 Easy Task
E - Easy Task Description Calculating the derivation of a polynomial is an easy task. Given a functi ...
- Codeforces 263A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #263 (Div. 2) A. Appleman and Easy Task【地图型搜索/判断一个点四周‘o’的个数的奇偶】
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...
- HD1046An Easy Task
Problem Description Ignatius was born in a leap year, so he want to know when he could hold his birt ...
- An Easy Problem?!(细节题,要把所有情况考虑到)
http://poj.org/problem?id=2826 An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
随机推荐
- linux_jdk_mysql_tomcat
1 linux下安装jdk的步骤: 0. 查找原有的jdk: rpm -qa | grep java 删除原有的jdk: rpm -e --nodeps java-1.7.0-openjdk-1.7. ...
- ARM ® and Thumb ®-2 指令系统
指令表关键词 Rm {, <opsh>} 寄存器移位方式,将寄存器的移位结果作为操作数而Rm值保持不变 <Operand2> 灵活的使用第二个操作数. ...
- Is there a way to detect if call is in progress? Phone Event
First you need 3 profiles to monitor the phone state: Event: Phone IdleVariable Clear %Phoning Event ...
- Tasker App Factory
http://tasker.dinglisch.net/userguide/en/appcreation.html App Creation Introduction Hello World Exam ...
- 四种更新UI的方法
笔记: // 使用handler.post(Runnable)更新UI public void updateUI_Fun1() { new Thread() { public void run() ...
- arcgis连接excel出现数据库失败 外部数据库驱动程序意外错误
微软搞事情,删除以下更新就行:win7 KB4041678 KB4041681SERVER 2008 R2 KB4041678 KB4041681WIN10 KB4041676 KB4041691SE ...
- iframe在ie和firefox中的高度兼容性问题解决
1.问题描述: <iframe src="p_photo_cont_iframe.html" name="iframe" width="700& ...
- Struts2 S标签 数目字格式化成金额输出(保留两位小数)
JSP: <s:property value="%{formatDouble(price)}" /> Action:添加 //格式化数字显示 public String ...
- mac securecrt无法记住密码的解决方法
打开secureCRT,菜单preferences--general,找到mac options.然后去掉Use KeyChain选项,这样每次连接服务器后就会自动保存密码了.不同的版本可能这个选项的 ...
- Common Internet File System
CIFS (Common Internet File System) is a protocol that gained popularity around the year 2000, as ven ...