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 ...
随机推荐
- Html学习(三) 分类学习
代码: <h1>这是一级分类吗</h1> <h2>这是二级分类吗</h2> <h3>这是三级分类吗 </h3> 效果: 介绍: ...
- RecyclerView借助ItemTouchHelper实现拖动和滑动删除功能
RecyclerView是官方推荐代替ListView的空间,怎样实现RecyclerView列表元素的拖动呢? 官方提供了ItemTouchHelper类使用过程例如以下: 定义ItemTouchH ...
- hdoj--2098--分拆素数和(水题)
分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- django 笔记14 中间件
用户请求->中间件->urls->views->返回字符串->中间件->用户浏览器 settings MIDDLEWARE里面都是中间件 有的地方叫管道 请求来的时 ...
- 安卓开发--HttpDemo01
package com.cnn.httpdemo01; import android.app.Activity; import android.content.Intent; import andro ...
- yii2.0缓存篇之页面缓存
页面缓存: 如果整个页面都不会发生改变,就可以使用页面缓存缓存整个页面. public function behaviors(){ //此方法[也叫行为]会提前控制器内其他方法执 ...
- Tomcat IO阻塞异常
tomcat的maxThreads.acceptCount(最大线程数.最大排队数) tomcat 的Connector配置如下 <Connector port="8080" ...
- 学习Go语言之观察者模式
首先了解一下观察者模式 1.目标和观察者抽象对象需要首先建立 //抽象主题 type Subject interface { Add(o Observer) Send(str string) } // ...
- 题解 P2610 【[ZJOI2012]旅游】
今天模拟赛考了这道题,那就来水一篇题解吧...(话说提高组模拟赛考什么省选题啊??) 这道题要我们求一条线段最多能经过的三角形数量. 回想小学学过的奥数,老师告诉过我们这样一件事:`点无大小 线无粗细 ...
- 【习题 8-18 UVA - 1619】Feel Good
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用单调队列求出l[i]和r[i] 分别表示i的左边最近的大于a[i]的数的位置以及i右边最近的大于a[i]的数的位置. 则l[i]+ ...