B. An Easy Task

Time Limit: 1000ms
Case Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name: Main
Font Size: 
+
 
-

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

The first line contains an integer T (1 ≤ T ≤ 10) -- the number of test cases.



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

For each test case, output one integer in a single line -- the number of possible values of X, or “-1” if the answer is infinite.

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(简箪题)的更多相关文章

  1. HDU-1076-An Easy Task(Debian下水题測试.....)

    An Easy Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  2. 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 ...

  3. An Easy Task

    An Easy Task Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  4. HDU-------An Easy Task

    An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. ZOJ 2969 Easy Task

    E - Easy Task Description Calculating the derivation of a polynomial is an easy task. Given a functi ...

  6. Codeforces 263A. Appleman and Easy Task

    A. Appleman and Easy Task time limit per test  1 second memory limit per test  256 megabytes input  ...

  7. 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 ...

  8. HD1046An Easy Task

    Problem Description Ignatius was born in a leap year, so he want to know when he could hold his birt ...

  9. An Easy Problem?!(细节题,要把所有情况考虑到)

    http://poj.org/problem?id=2826 An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

随机推荐

  1. IIS Express并发数设置

    今天将之前的一个瓦片图的服务迁移到了asp.net core试了一下,使用的时候感觉客户端刷新时有些慢,估计是并发连接数限制的原因. 由于这是一个开发中的版本,是用IIS Express部署的,IIS ...

  2. OPC Server开发的几大境界

    OPC server的开发相对OPC client 更加困难,OPC server 的开发主要应用COM技术,主要应用书籍为潘爱民写的<COM入门和应用>,大量的技术有很大的可重用性,在开 ...

  3. 查看是否安装.NET Framework、.NET Framework的版本号、CLR版本号

    查看是否安装.NET Framework→%SystemRoot%\System32→如果有mscoree.dll文件,表明.NET Framework已安装 查看安装了哪些版本的.NET Framw ...

  4. MVC二级联动使用$.ajax方法获取后端返回的字符串

    在"MVC二级联动使用$.getJSON方法"中使用$.getJSON()获取后端返回的JSon. 本篇使用jQuery的$.ajax()获取后端返回的字符串,实现二级联动.   ...

  5. Animatepacker for cocos2d-x 3.0 解析

    AnimatePacker 是大神老G为cocos2d-x2.0做的一个很简洁的工具 近期 e 的新项目用的是最新的cocos2d-x 3.0,因此改进了对应的解析代码 说明: 1.工具还是用的之前的 ...

  6. 深度学习阅读列表 Deep Learning Reading List

    Reading List List of reading lists and survey papers: Books Deep Learning, Yoshua Bengio, Ian Goodfe ...

  7. coursera课程Text Retrieval and Search Engines之Week 1 Overview

    Week 1 OverviewHelp Center Week 1 On this page: Instructional Activities Time Goals and Objectives K ...

  8. Intel® Core™ i5-5300U Processor

    3M Cache, up to 2.90 GHz Specifications Ordering and Compliance Essentials     Product Collection 5t ...

  9. 我所遭遇过的中间件--3D MAX SDK

    搞图形的人都知道3D MAX,而3D MAX SDK就是在该软件基础上的一套软件开发包.至于该不该将3D MAX SDK归纳为中间件,不要在意这细节了,反正我觉得SDK和中间件就差不多是一个东西.实际 ...

  10. max-sum-of-sub-matrix-no-larger-than-k

    根据上一篇文章提到的参考文档: https://leetcode.com/discuss/109749/accepted-c-codes-with-explanation-and-references ...