A:
英语阅读题,没读懂题意,这个题出的严重不好,有兴趣的可以做一下,从后往前求即可;

B:
题让你求每一步操作之后能mess up的数字(1-100)。每一步操作可能是加减乘除,mess up的定义是出现负数或者小数。
按照题意进行模拟就行了,注意坑点:mess up的数字不会再次进行操作。(比如4 -> 4/3 -> 4/3*3这种情况)

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define rep(i,a,b) for(int i = a;i <= b;++ i)
 4 #define per(i,a,b) for(int i = a;i >= b;-- i)
 5 #define mem(a,b) memset((a),(b),sizeof((a)))
 6 #define FIN freopen("in.txt","r",stdin)
 7 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
 8 #define pb push_back
 9 typedef long long LL;
10 typedef pair<int, int> PIR;
11 const int N = 1e6+5;
12 
13 int n;
14 bool vis[1005];
15 double a[N], x[N];
16 string op[N];
17 
18 int main()
19 {
20     cin >> n;
21     rep(i, 1, n)    cin >> op[i] >> x[i];
22     rep(i, 1, 100)  a[i] = i;
23     mem(vis, false);
24     int ans = 0;
25     rep(i, 1, 100){
26         rep(j, 1, n){
27             int res = a[i];
28             if(a[i] < 0 || res*1.0 != a[i]) continue;
29             if(op[j][0] == 'A')    a[i] += x[j];
30             if(op[j][0] == 'S')    a[i] -= x[j];
31             if(op[j][0] == 'M')    a[i] *= x[j];
32             if(op[j][0] == 'D')    a[i] = a[i]*1.0/x[j];
33         }
34         //cout << "a[i]: " << a[i] << endl;
35         int res = a[i];
36         if(a[i] < 0 || res*1.0 != a[i]) { vis[i] = true; ans++; }
37     }
38     cout << ans << endl;
39     return 0;
40 }
View Code

相关文章: