判断 Gym 100502K Train Passengers
1 /*
2 题意:几个判断,车上的人不能 <0 或 > C;车上初始和结束都不能有人在 (为0);车上满员时才有等候的人
3 水题:难点在于读懂题目意思,状态不佳,一直没搞懂意思,在这题卡住了
4 主要要理解have to wait 的意思
5 */
6 #include <cstdio>
7 #include <iostream>
8 #include <algorithm>
9 #include <cstring>
10 #include <string>
11 #include <cmath>
12 #include <set>
13 #include <map>
14 #include <queue>
15 using namespace std;
16
17 const int MAXN = 1e2 + 10;
18 const int INF = 0x3f3f3f3f;
19 int l[MAXN], e[MAXN], w[MAXN];
20
21 int main(void) //Gym 100502K Train Passengers
22 {
23 //freopen ("K.in", "r", stdin);
24
25 int C, n;
26
27 while (scanf ("%d%d", &C, &n) == 2)
28 {
29 int i;
30 for (i=1; i<=n; ++i)
31 {
32 scanf ("%d%d%d", &l[i], &e[i], &w[i]);
33 }
34 long long sum = 0;
35 for (i=1; i<=n; ++i)
36 {
37 if (i == n && w[i] > 0) {puts ("impossible"); break;};
38 sum -= l[i];
39 if (sum < 0 || sum > C) {puts ("impossible"); break;};
40 sum += e[i];
41 if (sum < 0 || sum > C) {puts ("impossible"); break;};
42 if (w[i] > 0 && sum < C) {puts ("impossible"); break;}; //当时没理解题意,写不出来:)
43 }
44
45 if (i > n)
46 {
47 if (sum != 0) puts ("impossible");
48 else puts ("possible");
49 }
50 }
51
52 return 0;
53 }
54
55 /*
56 impossible
57 possible
58 */
编译人生,运行世界!