题目链接:

  http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797

题目大意:

  有N个车站,火车一共可以坐M个人,每个车站下车Ai,上车Bi个人,在车站等待下一班Ci个人。问输入是否合法。

  合法:火车上的人不超过M,第一站不能有人下车,最后一站不能有人上车,火车满的时候才能有人在车站等下一班。

题目思路:

  【图论】

  签到水题。模拟到达每个车站的状态即可。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 104
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int a[N],b[N],c[N];
bool work()
{
int i,j,sum=;
for(i=;i<=n;i++)
{
sum-=a[i];
if(sum<)return ;
sum+=b[i];
if(sum>m)return ;
if(c[i]> && sum!=m)return ;
}
if(b[n]!= || c[n]!= || sum!=)return ;
return ;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s+1))
while(~scanf("%d",&m))
{
scanf("%d",&n);
ans=;
for(i=;i<=n;i++)
scanf("%d%d%d",&a[i],&b[i],&c[i]);
if(work())puts("possible");
else puts("impossible");
}
return ;
}
/*
// //
*/

【模拟】NCPC 2014 K Train passengers的更多相关文章

  1. 判断 Gym 100502K Train Passengers

    题目传送门 /* 题意:几个判断,车上的人不能 <0 或 > C:车上初始和结束都不能有人在 (为0):车上满员时才有等候的人 水题:难点在于读懂题目意思,状态不佳,一直没搞懂意思,在这题 ...

  2. CodeForcesGym 100502K Train Passengers

    Train Passengers Time Limit: 1000ms Memory Limit: 524288KB This problem will be judged on CodeForces ...

  3. 【模拟】NCPC 2014 E ceremony

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1791 题目大意: N栋大楼(N<=100000),拆除的时候有两种选择的操作,可 ...

  4. 【模拟】NCPC 2014 D Dice Game

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1790 题目大意: 两个人,每个人有两个骰子,每个骰子可以等概率取[a,b],问哪个人两 ...

  5. 模拟 Coder-Strike 2014 - Round 1 A. Poster

    题目地址:http://codeforces.com/problemset/problem/412/A /* 模拟:题目没看懂,但操作很简单,从最近的一头(如果不在一端要先移动到一端)往另一头移动,顺 ...

  6. 【高精度】NCPC 2014 C catalansqure

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1789 题目大意: 求大卡特兰数..公式如下.输入n求Sn(n<=5000) 题目 ...

  7. 【动态规划】【缩点】NCPC 2014 G Outing

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1793 题目大意: 一辆公交车,上面M个座位,N个人(M<=N<=1000) ...

  8. 【KMP】【最小表示法】NCPC 2014 H clock pictures

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...

  9. 【图论】【宽搜】【染色】NCPC 2014 A Ades

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1787 题目大意: N个点M条无向边(N,M<=200000),一个节点只能有一个 ...

随机推荐

  1. My-sql #1045 - Access denied for user 'root'@'localhost' (using password: NO)

    当你重装数据库后出现这个问题的时候,不要着急,首先你要去你的确定你的数据库已经成功的把服务开启了, 然后确定你的密码和账户,IP都确认的情况下, 去寻找config.inc.php 这个文件,根据配置 ...

  2. maven 依赖冲突的问题

    如果原始系统的jarA依赖jarB1.0 而新引入的jarC依赖jarB2.0 导致系统启动报错,提示冲突,这时为了保证原始系统的稳定性, 在pom.xml文件中引入jarC时,需要exclude掉j ...

  3. 判断浏览器是否支持FileReader

    1.js代码: //判断浏览器是否支持FileReader if (typeof FileReader == "undefined") { document.write(" ...

  4. Building Local Unit Tests

    If your unit test has no dependencies or only has simple dependencies on Android, you should run you ...

  5. oracle 数据库关闭的的几种方式总结

    shutdown的几种方式,shutdown abort的一些弊端有哪些   1.shutdown normal        正常方式关闭数据库.    2.shutdown immediate   ...

  6. app图标和启动页设置

    弄了一下午,终于把iOS中图标的设置和启动页的设置弄明白了.我想以后再也不会浑了. 进入正题: 一:apple 1).iPhone4s 3.5寸屏,也就是640*960,但在模拟器上正常用的是320* ...

  7. iOS-NSSDate的使用

    取当前时间的秒数 NSTimeInterval time = [[NSDate date] timeIntervalSince1970];long long int date = (long long ...

  8. 【转】iOS使用NSMutableAttributedString实现富文本

    iOS使用NSMutableAttributedString实现富文本 在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘 ...

  9. Spring_DI利用set方法赋值Demo

    Person.java public class Person { private Long pid; private String pname; private Student student; p ...

  10. ZOJ 刷题记录 小黑屋 (`・д・´)

    P1006:模拟 然而我的同余方程能过样例然而就是WA⊙﹏⊙b [已查明:扩展欧几里得算法出了很隐蔽的问题] int exGcd(int x,int y,int& a,int& b) ...