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 ...
随机推荐
- Python知识(6)--numpy做矩阵运算
矩阵运算 论numpy中matrix 和 array的区别:http://blog.csdn.net/vincentlipan/article/details/20717163 matrix 和 ar ...
- windows组策略和共享
Author: Jin Date: 20140585 ENV: win2008 R2 5年没弄windows了,现在随便弄弄,说实话不太喜欢windows,不出问题时候很方便,一出问题很头大.所有东西 ...
- Clever Little Box 电缆组件 USB A 插座 至 USB B 插头
http://china.rs-online.com/web/p/usb-cable-assemblies/7244156/ 产品详细信息 USB3.0适配器 superspeed USB将提供10x ...
- MP1593 RT8272 ACT4070 制作的DC-DC稳压电源
http://www.ideyi.org/article/11-05/2575971305526398.html?sort=2068_2073_2092_0 MP1593制作的DC-DC稳压电源,这款 ...
- MVC实现有关时间的进度条,使用jQuery ui的progressbar
在电商网站中,有时候通过进度条来直观地显示用户是否到期以及用户当前的状态. 设计这样的一个Model. public class User { public int Id { get; set; } ...
- 命令行编译工具NMAKE
简介 大家已经习惯于微软提供的功能强大的IDE,已经很少考虑手动编连项目了,所谓技多不压身,有空的时候还是随我一块了解一下命令行编译. C/C++/VC++程序员或有Unix/Linux编程经验应该很 ...
- 算法:哈希表格(Hash Table)
背景 Java 和 .Net 平台都有一个所有引用类型都会间接或直接继承的类型:Object,这个类型提供最基本的相等性比较算法和哈希算法,很多书上都给出了在重写这两个算法的时候的主意事项,其中大多数 ...
- python接口自动化4-绕过验证码登录(cookie)
前言 有些登录的接口会有验证码:短信验证码,图形验证码等,这种登录的话验证码参数可以从后台获取的(或者查数据库最直接). 获取不到也没关系,可以通过添加cookie的方式绕过验证码. 一.抓登录coo ...
- C# 模拟网站登陆
实现此功能首先需要借助一些抓包工具,对相应的网站登陆过程进行分析,此过程根据网站的不同,可能复杂,也可能很简单.常用的抓包工具FF下FireBug和IE下的HttpWatch.这两个工具很强大,以此工 ...
- eclipse无法启动
-startupplugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar-showsplashorg.eclipse.platfo ...