CodeForcesGym 100502K Train Passengers
Train Passengers
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 = ;
bool flag = true;
for(int i = ; i < n; ++i){
scanf("%d %d %d",&left,&went,&wait);
if(cur - left < ) flag = false;
cur += went - left;
if(cur > C || cur < C && wait) flag = false;
}
if(cur != ) flag = false;
return flag;
}
int main(){
int n,C;
while(~scanf("%d %d",&C,&n))
printf("%spossible\n",check(n,C)?"":"im");
return ;
}
CodeForcesGym 100502K Train Passengers的更多相关文章
- 判断 Gym 100502K Train Passengers
题目传送门 /* 题意:几个判断,车上的人不能 <0 或 > C:车上初始和结束都不能有人在 (为0):车上满员时才有等候的人 水题:难点在于读懂题目意思,状态不佳,一直没搞懂意思,在这题 ...
- 【模拟】NCPC 2014 K Train passengers
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797 题目大意: 有N个车站,火车一共可以坐M个人,每个车站下车Ai,上车Bi个人,在 ...
- 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)
You are given a list of train stations, say from the station 111 to the station 100100100. The passe ...
- B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
You are given a list of train stations, say from the station 1 to the station 100. The passengers ca ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Train Seats Reservation
You are given a list of train stations, say from the station 11 to the station 100100. The passenger ...
- CodeForcesGym 100676G Training Camp
G. Training Camp Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- 清华学堂 列车调度(Train)
列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...
- Organize Your Train part II-POJ3007模拟
Organize Your Train part II Time Limit: 1000MS Memory Limit: 65536K Description RJ Freight, a Japane ...
随机推荐
- 数学之路-python计算实战(6)-numpy-ndarray
>>>> mya=np.zeros(shape=(2,2)) >>>> mya array([[ 0., 0.], [ 0., 0.]]) > ...
- linux安装oracleclient
1.准备好所须要的安装包,http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html这个网 ...
- Leaflet--建设移动设备友好的互动地图
Leaflet 是一个为建设移动设备友好的互动地图,而开发的现代的.开源的 JavaScript 库.它是由 Vladimir Agafonkin 带领一个专业贡献者团队开发,尽管代码仅有 33 KB ...
- Func委托和Action委托
http://stackoverflow.com/questions/4317479/func-vs-action-vs-predicate The difference between Func a ...
- BZOJ 2049 LCT
思路:LCT的基本操作 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm&g ...
- Android中的Junit测试
在开发中Junit测试可以很方便的帮助开者尽可能早的发现并处理问题,而且使用也非常简单,只需要导入Junit测试相关的jar包并创建测试类,就可以对业务功能进行测试,而不用为了测试在代码中添加输出语句 ...
- 日前加拿大平板厂商 Datawind和印度运营商Reliance Communications日前宣布合作
全球最便宜智能手机只要15美元 随着手机进入智能时代,这些年智能手机的发展可谓迅猛,苹果三星这样的手机厂商成为最大的受益者同时,低门槛也让越来越多的人开始意识到,全民智能时代确实要来了. 为了能让第三 ...
- sql笔试题-1
在oracle下sql:比较巧妙地是group by 部分 E from (select a.team,b.y from nba a,nba b ) c group by (c.y-rownum) o ...
- ios发布以后关键信息确认与nslog
发布以后信息查看的路径: xcode->window->devices and …->查看如图的log. 通常在发布以后,处于安全和性能的考虑,会禁止打印log:但是在关键的信息需要 ...
- 海量的超赞 Linux 软件 (转载)
海量的超赞 Linux 软件 作者: VoLuong 译者: LCTT Mo | 2016-08-24 16:01 评论: 27 收藏: 38 这个仓库收集了对任何用户/开发者都超赞的 Linux ...