An Easy Task(简箪题)

B. An Easy Task

Time Limit: 1000ms

Case Time Limit: 1000ms

Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name: Main

Submit Status PID:
35999

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);

    }
}

时间: 2024-12-27 21:28:29

An Easy Task(简箪题)的相关文章

哈理工2015暑假训练赛BNU16488 Easy Task(简单题)

A - Easy Task Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatusPracticeZOJ 2969 Description Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivatio

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

An Easy Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17062    Accepted Submission(s): 10902 Problem Description Ignatius was born in a leap year, so he want to know when he could hold h

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

An Easy Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17062    Accepted Submission(s): 10902 Problem Description Ignatius was born in a leap year, so he want to know when he could hold h

[ACM] ZOJ 3844 Easy Task (模拟+哈希)

Easy Task Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these n integers. And then you should replace both a and bwith a-b. Yo

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=2 1.2.5 #include<stdio.h> /* 题意:找闰年. if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855 12 2004 10000 2108 1904 43236 */ int main() { int t,y,n; int i,count=0; whil

ZOJ 2969: Easy Task

ZOJ 2969: Easy Task 1 ///@date 2017-02-07 2 ///@author Sycamore, ZJNU 3 #include <iostream> 4 using namespace std; 5 int c[1001]; 6 int main() 7 { 8 int T; 9 cin >> T; 10 while (T--) 11 { 12 int N; 13 cin >> N; 14 for (int i = N; i >=

HDU-------An Easy Task

An Easy Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4088 Accepted Submission(s): 2327   Problem Description Ignatius was born in a leap year, so he want to know when he could hold his bir

2016 省热身赛 Easy Task

Easy Task Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these nintegers. And then you sho

CodeForces462 A. Appleman and Easy Task

A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you