An Easy Task(简箪题)
来源:互联网 发布:paparecipe验证软件 编辑:程序博客网 时间:2024/06/07 04:56
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
12> 2<= 5
Sample Output
3
#include<stdio.h>#define ll long long#define inf 9999999999int 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 (水)
- hdu 1076 An Easy Task (水题)
- hdu 1076(An Easy Task)
- HDU 1076 An Easy Task(水~)
- hdu1076 An Easy Task(C语言)
- 1076 An Easy Task
- An Easy Task
- An Easy Task
- An Easy Task
- An Easy Task
- 1076 An Easy Task
- hdu An Easy Task
- hdu1076 An Easy Task
- 1076 An Easy Task
- An Easy Task
- An Easy Task HDU1076
- An Easy Task
- 【代码实现】PHP生成各种随机验证码
- 在字符串中找出连续最长的数字串 ——来自华为OJ平台测试基础篇
- linux驱动---DMA操作---寄存器分析
- 关于无法打开包含文件:“fstream.h” 的问题
- cpp文件调用CUDA .cu文件实现显卡加速相关编程
- An Easy Task(简箪题)
- 学习心得
- vs2010 qt addin
- Android_ViewPager基础+Fragment_141008
- Android_Fragment解析(1)+transaction_141009
- win7 qt5 oracle11g 64位下编译oci驱动
- Shellshock漏洞那些事:网络安全噩梦的开始
- ㊙ 女士尽量不要称爱人为“老公”
- Android_Fragment解析(2)+Activity通信+防重构_141010