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");
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值