ACdream

来源:互联网 发布:java excel 小数 4位 编辑:程序博客网 时间:2024/05/02 13:43

Can you make a water problem?

Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

Problem Description

Losanto want to make a water problem. But he have no idea….
Then he thought a problem: A bus arrived at a station, and there were x persons got off the bus, then y persons got on the bus. And there were r persons(include the driver) on the bus before the bus arrived at next station. How many person on the bus initially? The driver can’t get on or off the bus. There is only 1 driver in the bus.
But if the x=8 , y=5 r=4, there are something wrong in the problem. After got on 5 persons and there are 4 persons rest…What a pity! Losanto give you x, y, r want know whether the problem is OK.
Of course few buses has only one station, so there are n stations.
Now give you x and y for every station, and there is only one person (the driver) rest after the last station. Can you find a suitable order for the station to make the problem OK?

Input

There are several cases.

For each case, First line there is a n, indicate n stations. Then n lines followed, each line has two numbers xi and yi. To make the problem easier, we guarantee that xi>=yi.(0<n<100000  0<=xi,yi<1000000)

Output

For each cases, output one line with “Yes” (if you can make an OK order) or “No” (if you can’t).

Sample Input

25 07 425 23 3

Sample Output

YesNo

Source

第九届北京化工大学程序设计竞赛

Manager

rihkddd

题目大意是:有一辆巴士。一个巴士有n个站台。当巴士到达一个站台时,有x人下车,有y人上车。当汽车到达下一个站台时,车上还有r个人(包括司机)。
                     注意点1:每辆巴士只有一个司机
                                 2:司机在巴士到达第一个站台前已经在车上了。且司机在到达最后一个站台时,不会下车。
                                 3:汽车在到达第一个车站前,车上就已经有r个人了。
                                 4:到达最后一站时,车上除了司机之外的人全部下车。
                                5:综上,从头到尾,本题和司机没啥关系。不用考虑司机。

                         然后,让你输入n组数据,每组数据包含一个xi和yi。但xi和yi不确定是哪个车站的上下车人数。然后让你判断这n组数据是否符合常理,及是:按照这n组数据的上下车方式,是否符合现实。我们先把n组数据按照从y从小到大排序。然后倒过来推导,看看是否满足逻辑。
正序推导:

从上图得知,R必须大于x,否则不符合逻辑。(因为是先下车,后上车)
倒序推导:




可知R=y-x
所以
该题必须满足R>x


上代码
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;struct ssr{    int x,y;} re[100005];bool cmp( ssr x,ssr y){    return x.y>y.y;}int main(){    int n;    while(cin>>n)    {        for(int i=1; i<=n; i++)        {            scanf("%d %d",&re[i].x,&re[i].y);///下x人,上y人        }        sort(re+1,re+1+n,cmp);//        for(int i=1; i<=n; i++)//        {//            printf("%d %d\n",re[i].x,re[i].y);//        }        long long sum=0;///此处要用long long                int flag=1;        for(int i=n; i>=1; i--)        {            sum+=re[i].x-re[i].y;///此处的sum相当于r                        if(sum<re[i].x)///sum必须大于x            {                flag=0;                break;            }        }        if(flag)        {            printf("Yes\n");        }        else        {            printf("No\n");        }    }    return 0;}

O(∩_∩)O

0 0
原创粉丝点击