Topic links
Time limit: 10000ms single point time limit: 1000ms memory Limit: 256MB describes the number of inequalities that are given n about X, and how many of them are established. Each inequality is one of the following forms: X < cx <= CX = CX > CX >= C Enter the first line an integer n. The following n rows, one inequality per line. Data range: 1<=n<=50,0<=c<=1000 outputs an integer that represents the maximum number of inequalities that can be set at the same time. Example input 4X = 1X = 2X = 3X > 0 Sample Output 2
Thinking of solving problems
Record the symbol and constant c for each inequality, and finally enumerate X to find out the number of inequalities that can be set up at the same time, noting that x is not an integer
#pragma COMMENT (linker, "/stack:102400000,102400000") #include <iostream> #include <cstdio> #include < string> #include <cstring> #include <iomanip> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <map> #include <fstream>using namespace Std;typedef long Long ll;const int INF = 0x3f3f3f3f;const int MAX = 0x7fffffff;const ll linf = 0x3f3f3f3f3f3f3f3f;const ll LMAX = 0x7fffffffffff Ffff;const double Pi=acos ( -1.0), const int MAXN = 100000+5;const int maxm = 100000+5;const int mod = 1000000007; #define LSO n l,m,rt<<1#define rson m+1,r,rt<<1|1struct node{int op; int C;} Data[50+5];int strtoint (String S,int index) {int re=0; for (int i=index; i<s.length (); ++i) {re=re*10+s[i]-' 0 '; } return re;} int main () {//freopen ("Input.txt", "R", stdin); Freopen ("Output.txt", "w", stdout); int n; while (Cin>>n) cin>>n; {GetChar (); StringS int C; for (int i=1; i<=n; ++i) {cin>>s>>s>>c; Data[i].c=c; if (s== "<") {data[i].op=1; } else if (s== "<=") {data[i].op=2; } else if (s== "=") {data[i].op=3; } else if (s== ">=") {data[i].op=4; } else {data[i].op=5; }} int ans=0; for (double x=-0.5; x<=1000.5; x+=0.5) {int num=0; for (int j=1, j<=n; ++j) {switch (DATA[J].OP) {Case 1: if (X<DATA[J].C) num++; Break Case 2:if (X<=DATA[J].C) num++; Break Case 3: if (X==DATA[J].C) num++; Break Case 4:if (X>=DATA[J].C) num++; Break Case 5:if (X>DATA[J].C) num++; Break }} Ans=max (Num,ans); } cout<<ans<<endl; } return 0;}Summarize
Made a lot of mistakes, are some of the details.
Starting with getline () read, x As Integer processing, x from 0 to 1000, wrong three times, 4 a
Hihocoder Challenge 14-1223 inequality