Given a set of constraints like 0<N<=M<=100 and values for all the variables, write a checker program to determine if the constraints are satisfied.
More precisely, the format of constraints is:
token op token op ... op token
where each token is either a constant integer or a variable represented by a capital letter and each op is either less-than ( < ) or less-than-or-equal-to ( <= ).
The first line contains an integer N, the number of constraints. (1 ≤ N ≤ 20)
Each of the following N lines contains a constraint in the previous mentioned format.
Then follows an integer T, the number of assignments to check. (1 ≤ T ≤ 50)
Each assignment occupies K lines where K is the number of variables in the constraints.
Each line contains a capital letter and an integer, representing a variable and its value.
It is guaranteed that:
1. Every token in the constraints is either an integer from 0 to 1000000 or an variable represented by a capital letter from 'A' to 'Z'.
2. There is no space in the constraints.
3. In each assignment every variable appears exactly once and its value is from 0 to 1000000.
For each assignment output Yes or No indicating if the constraints are satisfied.
样例输入 2 A<B<=E 3<=E<5 2 A 1 B 2 E 3 A 3 B 5 E 10 样例输出 Yes No #pragma comment(linker, "/STACK:102400000,102400000") #include <algorithm> #include <iostream> #include <iomanip> #include <sstream> #include <cstring> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> #include <queue> #define Pi acos(-1.0) using namespace std; typedef long long ll; struct ListNode { int lei; char al; ll val; int op; ListNode *next; ListNode():next(NULL){} }; int n; ListNode* p[21]; ListNode* rem[21]; ListNode* rrem[21]; char str[22][222222]; map<char,ll>mp; int fun(){ for(int i = 0;i < n;i++){ rrem[i] = rem[i]; while(rrem[i] != NULL && rrem[i]->next !=NULL){ ll pre,last; int nowop = rrem[i]->op; //printf("op :%d\n", nowop); if(rrem[i]->lei == 1) pre = mp[rrem[i]->al]; else pre = rrem[i]->val; rrem[i] = rrem[i]->next; if(rrem[i]->lei == 1) last = mp[rrem[i]->al]; else last = rrem[i]->val; if((nowop == 1 && pre <= last) || (nowop==2 && pre < last)) continue; else return 0; } } return 1; } /* void test(){ for(int i = 0; i < n;i++){ rrem[i] = rem[i]; while(rrem[i]!= NULL){ if(rrem[i]->lei==1) printf("%d ", mp[rrem[i]->al]); else printf("%d ", rrem[i]->val); rrem[i] = rrem[i]->next; } printf("\n"); } }*/ int main(){ mp.clear(); scanf("%d", &n); { mp.clear(); for(int i = 0;i < n;i++){ p[i] = new ListNode(); rem[i] = p[i]; } for(int i = 0;i < n;i++){ scanf("%s", str[i]); ll num = 0; for(int j = 0;str[i][j]!=0;j++){ if(str[i][j] >= 'A' && str[i][j] <= 'Z'){ mp[str[i][j]] = 1; p[i]->lei = 1; p[i]->al = str[i][j]; } else if(str[i][j] >= '0' && str[i][j] <= '9'){ num = num * 10 + str[i][j] - '0'; if(str[i][j+1]==0){ p[i]->val = num; p[i]->lei = 0; num = 0; } } else if(str[i][j]=='<'){ if(str[i][j+1]=='='){ p[i]->op = 1; } else{ p[i]->op = 2; } if(str[i][j-1] >= '0' && str[i][j-1] <= '9'){ p[i]->lei = 0; p[i]->val = num; num = 0; } p[i]->next = new ListNode(); p[i] = p[i]->next; } } } int cnt = 0; for(int i = 0; i < 26;i++){ if(mp[i+'A']) cnt++; } int m; scanf("%d", &m); int ans[222]; for(int i = 0;i < m;i++){ char op[10]; for(int j = 0;j < cnt;j++){ ll x; scanf("%s%lld", op, &x); mp[op[0]] = x; } // test(); ans[i] = fun(); } for(int i = 0;i < m;i++){ if(ans[i]==1){ printf("Yes\n"); } else{ printf("No\n"); } } } }