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 <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define Len 200005
#define mod 360000
const int INF = 0x3f3f3f3f;
#define exp 1e-6

int main()
{
    LL C,n,sum,w,a,b,c;
    w(scanf("%lld%lld",&C,&n)>0)
    {
        sum=0;
        w=0;
        int flag=0;
        w(n--)
        {
            scanf("%lld%lld%lld",&a,&b,&c);
            if(flag)
                continue;
            if(sum<a)
            {
                flag=1;
                continue;
            }
            sum=sum-a+b;
            if(sum>C)
                flag=1;
            if(sum!=C && c) flag = 1;
            if(!n && (sum || b || c)) flag = 1;
        }
        if(flag)
            printf("impossible\n");
        else
            printf("possible\n");
    }
}

时间: 2024-10-06 10:29:23

CSU1584: Train Passengers的相关文章

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

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++.

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

Train Problem II 卡特兰裸题(入门题)

Train Problem II  题目大意:给你一个数n,表示有n辆火车,编号从1到n,从远方驶过来,问你有多少种出站的可能. 解题思路:模拟栈的问题而已.  卡特兰问题. 1 import java.math.*; 2 import java.util.*; 3 import java.io.*; 4 5 public class Main 6 { 7 static int MS=101; 8 public static void main(String[] args) 9 { 10 Sca

POJ3007(Organize Your Train part II)

传送门 Organize Your Train part II Time Limit: 1000MS   Memory Limit: 65536K       Description RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown i