#1223: Inequalities
Time Limit:1 Sec
Memory limit:256 MB
Topic Connection http://hihocoder.com/problemset/problem/1223
Description
Given n an inequality about X, the maximum number of questions is set.
Each inequality is one of the following forms:
X < C
X <= C
X = C
X > C
X >= C
Input
The first line is an integer n.
The following n rows, one inequality per line.
Data range:
1<=n<=50,0<=c<=1000
OutputAn integer line that represents the maximum number of inequalities that can be set at the same time. Sample Input
4
X = 1
X = 2
X = 3
X > 0
Sample Output2
HINT
Test instructions
Exercises
Enumerate each number directly, for each number, determine how much data is satisfied
Of course, the data range is larger than the problem, then you have to discretization and update the interval, the last query maximum value is good
Overall, the idea is the same.
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 1200051#defineMoD 10007#defineEPS 1e-9intNum;//const int INF=0X7FFFFFFF; //нчоч╢сConst intinf=~0u>>1; inline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************stringstr[ -],x;intnum[ -];intMain () {intn=read (); for(intI=1; i<=n;i++) {cin>>X>>str[i]>>Num[i]; Num[i]*=2; } intans=0; for(inti=-2; i<=2002; i++) { intTMP =0; for(intj=1; j<=n;j++) { intOK =1; if(str[j]=="<") if(i>=num[j]) OK=0; if(str[j]=="<=") if(i>num[j]) OK=0; if(str[j]=="=") if(i!=num[j]) OK=0; if(str[j]==">") if(i<=num[j]) OK=0; if(str[j]==">=") if(i<num[j]) OK=0; if(OK) TMP++; } ans=Max (Tmp,ans); } printf ("%d\n", ans);}
Hihocoder #1223: An inequality water problem