CodeForcesGym 100502K Train Passengers
2015-04-28 09:08
357 查看
Train Passengers
Time Limit: 1000msMemory Limit: 524288KB
This problem will be judged on CodeForcesGym. Original ID: 100502K
64-bit integer IO format: %I64d Java class name: (Any)
The Nordic Company of Passing Carriages is losing money at an alarming rate because most of their trains are empty. However, on some lines the passengers are complaining that they cannot fit in the cars and have to wait for the next train! The authorities want to fix this situation. They asked their station masters to write down, for a given train, how many people left the train at their station, how many went in, and how many had to wait. Then they hired your company of highly paid consultants to assign properly sized trains to their routes.
You just received the measurements for a train,but before feeding them to your optimisation algorithm you remembered that they were collected on a snowy day, so any sensible station master would have preferred to stay inside their cabin and make up the numbers instead of going outside and counting. Verify your hunch by checking whether the input is inconsistent, i.e., at every time the number of people in the train did not exceed the capacity nor was below 0 and no passenger waited in vain. The train should start and finish the journey empty, in particular passengers should not wait for the train at the last station.
Input
The first line contains two integers C and n (2 ≤ n ≤ 100), the total capacity and the number of stations the train stops in. The next n lines contain three integers each, the number of people that left the train, entered the train, and had to stay at a station. Lines are given in the same order as the train visits each station. All integers including C are between 0 and 109 inclusive.
Output
One line containing one word: possible if the measurements are consistent, impossible otherwise.
Sample Input 1
1 2
0 1 1
1 0 0
Sample Output 1
possible
Sample Input 2
1 2
1 0 0
0 1 0
Sample Output 2
impossible
Sample Input 3
1 2
0 1 0
1 0 1
Sample Output 3
impossible
Sample Input 4
1 2
0 1 1
0 0 0
Sample Output 4
impossible
解题:直接模拟就好
#include <bits/stdc++.h> using namespace std; typedef long long LL; bool check(int n,int C){ int left,went,wait; LL cur = 0; bool flag = true; for(int i = 0; i < n; ++i){ scanf("%d %d %d",&left,&went,&wait); if(cur - left < 0) flag = false; cur += went - left; if(cur > C || cur < C && wait) flag = false; } if(cur != 0) flag = false; return flag; } int main(){ int n,C; while(~scanf("%d %d",&C,&n)) printf("%spossible\n",check(n,C)?"":"im"); return 0; }
View Code
相关文章推荐
- Codeforces Gym 101158 A. Rearranging a Sequence
- 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)
- Codeforces Gym 100418J Lucky tickets 数位DP
- Codeforces Gym 100286G Giant Screen 水题
- Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面
- Codeforces Gym 100203I I - I WIN 网络流最大流
- Codeforces Gym 100650B Countdown DFS
- codeforces gym-101078
- [Trie树建图 2-SAT] Codeforces Gym 101190 NEERC 16 B. Binary Code
- CodeForcesGym 100641B A Cure for the Common Code
- codeforces Gym - 101190J ——Jenga Boom(模拟)
- Codeforces Gym 100002 C "Cricket Field" 暴力
- Codeforces Gym 100342F Move to Front 平衡树
- Codeforces Gym 100548F Color (组合数+容斥)
- Codeforces Gym - 101635K Blowing Candles [旋转卡壳]
- CodeForcesGym 100517I IQ Test
- CodeForcesGym 100753B Bounty Hunter II 二分图最小路径覆盖
- Codeforces Gym 100531D Digits (暴力、打表)
- UVA Live 6129 (Codeforces Gym 100642H) Sofa, So Good 最小费用流
- codeforces Gym - 100633J Ceizenpok’s formula