Sicily 13914. Train Passengers

13914. Train Passengers

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

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 &#20;<= n <=&#20; 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 2
0 1 1
1 0 0
样例二:
1 2
1 0 0
0 1 0
样例三:
1 2
0 1 0
1 0 1
样例四:
1 2
0 1 1
0 0 0

Sample Output

样例一:
possible
样例二:
impossible
样例三:
impossible
样例四:
impossible

Problem Source

2015年每周一赛第四场

#include <stdio.h>

int main() {
	bool possible = true;
	int c, n, m = 0, l, e, w;
	scanf("%d%d", &c, &n);
	while (n && n--) {
		scanf("%d%d%d", &l, &e, &w);
		if (!(0 <= l && l <= m)) possible = false;
		m -= l;
		if (!(0 <= e && e <= c - m)) possible = false;
		m += e;
		if (0 > w || (c > m && w > 0)) possible = false;
	}
	while (n--) scanf("%d%d%d", &l, &e, &w);
	printf(possible && !m ? "possible\n" : "impossible\n");
	return 0;
}
时间: 2024-08-01 22:46:54

Sicily 13914. Train Passengers的相关文章

CodeForcesGym 100502K Train Passengers

Train Passengers Time Limit: 1000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGym. Original ID: 100502K64-bit integer IO format: %I64d      Java class name: (Any) The Nordic Company of Passing Carriages is losing money at an ala

csu 1584 Train Passengers

#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<stack> #include<vector> #include<stdlib.h> #include<algorithm> using namespace std; int dir4[][2]={{0,1},{

【模拟】NCPC 2014 K Train passengers

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797 题目大意: 有N个车站,火车一共可以坐M个人,每个车站下车Ai,上车Bi个人,在车站等待下一班Ci个人.问输入是否合法. 合法:火车上的人不超过M,第一站不能有人下车,最后一站不能有人上车,火车满的时候才能有人在车站等下一班. 题目思路: [图论] 签到水题.模拟到达每个车站的状态即可. 1 // 2 //by coolxxx 3 //#include<bits/stdc++.

CSU1584: Train Passengers

Description Input Output Sample Input 1 2 0 1 1 1 0 0 Sample Output possible 题意:给出火车容量c,站点数n 对于每个站点给出上车人数,下车人数和等待人数 问最后是否能按要求完成旅途 思路:这道题理解了蛮久,后来得到如下确定 1.最后一站,计算完之后,必须车上无人,没人上车,没人等待 2.超出车的容量,必然不行 3.如果车没上满,却还有等待的人,那么是不行的,因为车没上满我干嘛不上啊,还等毛线啊 #include <io

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

(转)sicily题目分类

Sicily题目分类 ·         [数据结构/图论] 1310 Right-Heavy Tree   笛卡尔树相关,复杂度O(N)或O(NlogN). ·1426 Phone List         电话号码前缀检索,trie树相关. ·1443 Printer Queue      基本队列操作. ·1149 等价表达式         判断表达式是否等价(递归求解) ·1136 山海经             n长序列里求m次区间询问的最大连续子区间和.线段树/RMQ ·1252

HDU1022 Train Problem I (栈)

栈+队列 1 #include<stdio.h> 2 #include<string.h> 3 #include<stack> 4 #include<queue> 5 using namespace std; 6 int main() 7 { 8 int n; 9 char a[11],b[11]; 10 stack<char>s; 11 queue<int>q; 12 while(scanf("%d",&

HDU 1022 Train Problem I

描述As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there i

hdu 1022 Train Problem

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30588    Accepted Submission(s): 11561 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays