【模拟】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++.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<map>
 9 #include<stack>
10 #include<queue>
11 #include<set>
12 #include<bitset>
13 #include<memory.h>
14 #include<time.h>
15 #include<stdio.h>
16 #include<stdlib.h>
17 #include<string.h>
18 //#include<stdbool.h>
19 #include<math.h>
20 #define min(a,b) ((a)<(b)?(a):(b))
21 #define max(a,b) ((a)>(b)?(a):(b))
22 #define abs(a) ((a)>0?(a):(-(a)))
23 #define lowbit(a) (a&(-a))
24 #define sqr(a) ((a)*(a))
25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
26 #define mem(a,b) memset(a,b,sizeof(a))
27 #define eps (1e-8)
28 #define J 10
29 #define mod 1000000007
30 #define MAX 0x7f7f7f7f
31 #define PI 3.14159265358979323
32 #define N 104
33 using namespace std;
34 typedef long long LL;
35 int cas,cass;
36 int n,m,lll,ans;
37 int a[N],b[N],c[N];
38 bool work()
39 {
40     int i,j,sum=0;
41     for(i=1;i<=n;i++)
42     {
43         sum-=a[i];
44         if(sum<0)return 0;
45         sum+=b[i];
46         if(sum>m)return 0;
47         if(c[i]>0 && sum!=m)return 0;
48     }
49     if(b[n]!=0 || c[n]!=0 || sum!=0)return 0;
50     return 1;
51 }
52 int main()
53 {
54     #ifndef ONLINE_JUDGE
55 //    freopen("1.txt","r",stdin);
56 //    freopen("2.txt","w",stdout);
57     #endif
58     int i,j,k;
59 //    for(scanf("%d",&cass);cass;cass--)
60 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
61 //    while(~scanf("%s",s+1))
62     while(~scanf("%d",&m))
63     {
64         scanf("%d",&n);
65         ans=0;
66         for(i=1;i<=n;i++)
67             scanf("%d%d%d",&a[i],&b[i],&c[i]);
68         if(work())puts("possible");
69         else puts("impossible");
70     }
71     return 0;
72 }
73 /*
74 //
75
76 //
77 */

时间: 2024-07-31 14:27:20

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

hdu 4915 Parenthese sequence(模拟)2014多校训练第5场

Parenthese sequence                                                                     Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description bobo found an ancient string. The string contains only t

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

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 com

【模拟】NCPC 2014 E ceremony

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1791 题目大意: N栋大楼(N<=100000),拆除的时候有两种选择的操作,可以拆掉一整栋,或者把当前所有大楼的第x层拆掉(高度小于x的没用),并且x以上的所有楼层高度-1.(相当于所有高于x的大楼抽掉一层) 问把N栋大楼拆掉至少要几次拆除操作. 题目思路: [模拟] 先将大楼高度排序,之后考虑分界线,枚举I,I之后的大楼都是被单个拆除,而I和I之前的大楼都是被一层一层拆除.ans

【模拟】NCPC 2014 D Dice Game

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1790 题目大意: 两个人,每个人有两个骰子,每个骰子可以等概率取[a,b],问哪个人两个骰子期望和更大. 题目思路: [模拟] 签到水题.单个骰子的期望E=0.5*(b+a).所以只需要求和比大小就行. 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<a

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

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1793 题目大意: 一辆公交车,上面M个座位,N个人(M<=N<=1000),每个人只有在Ci也上车的情况下才上车.问最多上车几人. 题目思路: [动态规划][缩点] 首先这是一张N个点N条边的有向图.如果J在I也上车的情况下才上车则连一条I到J的边.这样每个点入度最多为1. 这张图有可能有环,所以先缩点,缩完点之后每个环不会有入边,且一定是一个子树的根节点.这样原来的有环的图就变成

【高精度】NCPC 2014 C catalansqure

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1789 题目大意: 求大卡特兰数..公式如下.输入n求Sn(n<=5000) 题目思路: [高精度] Sn=Cn+1.直接压四位高精度算一遍就好.只要写高精度乘单精度,高精度除单精度. 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algorith

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

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1787 题目大意: N个点M条无向边(N,M<=200000),一个节点只能有一个标记.每条边有一个值{0,1或2}表示这条边连接的两个节点拥有的标记之和.问只要要多少个标记才能满足,无解impossible. 题目思路: [图论][宽搜] 因为每个点只能有或没有标记.所以可以枚举每个联通块的其中一个点有还是没有标记,用这个点去拓展这个点的联通块并01染色(这个点所能到达的所有点) 初

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

题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个针都是相同的,分别指向Ai,Bi(360°被分成360000小份),问能否将其中一个旋转和另一个重合. 题目思路: [KMP][最小表示法] 循环同构问题.可以写KMP,我懒得写KMP了就写了循环同构的最小表示法. 首先将Ai排序,然后求差(记得取模360000,WA了一次),接下来复制一遍开始匹配. A