csu 1584: Train Passengers

题意:<span style="background-color: rgb(240, 240, 240); font-size: 12.025px;">1.最后一站,计算完之后,必须车上无人,没人上车,没人等待</span>
<span style="background-color: rgb(240, 240, 240); font-size: 12.025px;">2.超出车的容量,必然不行</span>
3.如果车没上满,却还有等待的人,那么是不行的,因为车没上满我干嘛不上啊,还等毛线啊
#include<cstdio> 
#include<cstring> 
#include<algorithm> 
using namespace std; 
  
int main() 
{ 
    long long C,n; 
    long long x,y,z; 
    int flag; 
    while(scanf("%lld%lld",&C,&n)==2) 
    { 
        long long num=0; 
        flag=1; 
        for(int i=1;i<=n;i++) 
        { 
            scanf("%lld%lld%lld",&x,&y,&z); 
            if(flag==0) 
                continue; 
            if(i<n&&x<=num&&y<C-num+x&&z==0) 
            { 
                num=num-x+y; 
                continue; 
            } 
            if(i<n&&x<=num&&y==C-num+x) 
            { 
                num=num-x+y; 
                continue; 
            } 
            if(i==n&&x==num&&y==0&&z==0) 
            { 
                continue; 
            } 
            flag=0; 
        } 
        if(flag) 
            printf("possible\n"); 
        else
            printf("impossible\n"); 
    } 
    return 0; 
} 


你可能感兴趣的:(c)