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. [Android] 字体使用dp单位避免设置系统字体大小对排版的影响

    [Android] 字体使用dp单位避免设置系统字体大小对排版的影响 以魄族mx3为例,在设置->显示->字体大小中能够选择字号大小例如以下图: 图1. 魄族mx3 会导致软件在有固定定高 ...

  2. Install WordPress Plugins without FTP Access

    WordPress will only prompt you for your FTP connection information while trying to install plugins o ...

  3. FT232H USB转串口,I2C,JTAG高速芯片

    随着FT232H USB2.0高速芯片的发布,英商飞特蒂亚公司(FTDI)进一步巩固了其在USB接口集成电路产品的地位.此款多功能的单通道USB转UART/FIFO接口设备可通过EEPROM配置为各种 ...

  4. jquery easyui combobox设置默认选中第一项

    combobox的内容是从后台获取的json, js截取: var data = $('#id').combobox('getData'); $("#id ").combobox( ...

  5. 制作MACOSX10.10.3/10.9安装启动盘U盘的教程

    下载MACOSX 10.10.3/10.9镜像文件,下载地址http://www.chinamac.com/download/mac14032.html1.准备好你需要的大于等于6G以上的U盘或者移动 ...

  6. 怎样用Java代码来把SSL的证书自己主动导入到Java的秘钥存储文件(keystore)

    我们在开发或者使用SSL的过程中,非常多的软件须要我们提供java的keystore.特别是一些基于Java的中间件产品. 我们常规的做法是JDK自带的工具命令(keytool)去做.比方,以下的样例 ...

  7. Android实例剖析笔记(三)

    摘要:点介绍Activity的生命周期,通过一个简单的实验来摸索状态转换的机制 Activity的生命周期 Activity类中有许多onXXX形式的函数可以重载,比如onCreate,onStart ...

  8. andriod 文本居中: android:gravity="center"

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  9. .NET:事务、并发、并发问题、事务隔离级别、锁等相关资料整理

    这里面的有三篇文章,必须要读读:http://technet.microsoft.com/en-us/library/ms189130(v=sql.105).aspx. 这里有一个系列,我还没有读:h ...

  10. Android网络通信Volley框架源代码浅析(二)

    尊重原创 http://write.blog.csdn.net/postedit/25921795 在前面的一片文章Volley框架浅析(一)中我们知道在RequestQueue这个类中,有两个队列: ...