Topic 1: Inequality time limit:10000msSingle Point time limit:1000msMemory Limit:256MBDescribe
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
Output
An integer line that represents the maximum number of inequalities that can be set at the same time.
-
Sample input
4X = 1X = 2X = 3X > 0
Sample output
2
This question does not say that C is an integer, but the commit code to the C as an integer can be AC, Solution: Enumeration x= -0.5,0,0.5, ... 1000.5 Check the number of inequalities that satisfy the condition, ans is the maximum value
#include <cstdio>#include<cstring>#include<string>#include<map>using namespacestd;Chars[Ten];Charst[Ten];intN;inta[2020];intMain () {scanf ("%d",&N); intx; for(intI=0; i<n;i++) {scanf ("%s", s); scanf ("%s", s); scanf ("%s", ST); SSCANF (St,"%d",&x); if(strcmp (s),"=")==0) {a[2* (x+1)]++; } Else if(strcmp (s),">")==0){ for(intj=2* (x+1)+1;j< .; j + +) A[j]++; }Else if(strcmp (s),">=")==0){ for(intj=2* (x+1);j< .; j + +) A[j]++; }Else if(strcmp (s),"<")==0){ for(intj=2*x+1; j>=0; j--) A[j]++; }Else if(strcmp (s),"<=")==0){ for(intj=2* (x+1); j>=0; j--) A[j]++; } } intAns =0; for(intI=0;i< .; i++){ if(Ans<a[i]) ans =A[i]; } printf ("%d\n", ans); return 0;}
Hihocoder Challenge 14 Topic 1: Inequalities