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

    一对多,多对多的关联时最后的参数 together说明 如果为false,分开查多个语句 如果为true,强制生成一个语句 如果没有设置,分页页生成多个语句,不分页时生成一个语句 多对多时,查询时,中 ...

  2. 【原】不定义Order属性,通过切面类的定义顺序来决定通知执行的先后顺序

    [结论] 在多个切面类的“切入点相同”并且每个切面都“没有定义order属性”的情况下,则切面类(中的通知)的执行顺序与该切面类在<aop:config>元素中“声明的顺序”相关,即先声明 ...

  3. Spring_Spring集成Quartz定时任务框架介绍和Cron表达式详解

    在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但 ...

  4. gulp编译出现Cannot find module 'internal/util/types'——node环境的变更

    一心埋头敲代码,再回首,nodejs都蹦跶到8.9版本了,为了跟上时代,妥妥的赶紧升级啊,升级的结果...Cannot find module 'internal/util/types'...   于 ...

  5. PowerDesigner导出表为Excel(转)

    打开脚本运行器Ctrl+Shift+X 导出: '*************************************************************************** ...

  6. Eclipse upper case/lower case

    How do I make a lower case string in Eclipse to be upper case?Using Eclipse, I want to select a stri ...

  7. ConcurrentHashMap JDK 1.6 源码分析

    前言 前段时间把 JDK 1.6 中的 HashMap 主要的一些操作源码分析了一次.既然把 HashMap 源码分析了, 就顺便把 JDK 1.6 中 ConcurrentHashMap 的主要一些 ...

  8. RPM 打包技术与典型 SPEC 文件分析

    一 .rpm 介绍 1. 概述 RPM全称是 Red Hat Package Manager(Red Hat包管理器).几乎所有的 Linux 发行版本都使用这种形式的软件包管理安装.更新和卸载软件. ...

  9. java多线程实现主线程等待子线程执行完问题

    本文介绍两种主线程等待子线程的实现方式,以5个子线程来说明: 1.使用Thread的join()方法,join()方法会阻塞主线程继续向下执行. 2.使用Java.util.concurrent中的C ...

  10. LDAP 总结

    LDAP入门 首先要先理解什么是LDAP,当时我看了很多解释,也是云里雾里,弄不清楚.在这里给大家稍微捋一捋. 首先LDAP是一种通讯协议,LDAP支持TCP/IP.协议就是标准,并且是抽象的.在这套 ...