zoukankan      html  css  js  c++  java
  • ACDream 1734 Can you make a water problem?(贪心)

    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

    2
    5 0
    7 4
    2
    5 2
    3 3

    Sample Output

    Yes
    No

    Manager

     
    题意:有n个站,给出每个站的下车人数xi和上车人数yi,问怎么把站排序使得符合客观条件。
    分析:把站按照上车人数从多到少排序,然后判断下是否符合客观条件,即,车上的人数应该不小于下车的人数。
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stdlib.h>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<algorithm>
    #define LL long long
    using namespace std;
    const int MAXN=100000+5;
    LL tot;
    int n;
    struct node
    {
        int x,y;
        bool operator<(const node A)const
        {
            return x-y>A.x-A.y;
        }
    }a[MAXN];
    bool cheak()
    {
        for(int i=0;i<n;i++)
        {
            if(tot<a[i].x) return false;
            tot-=a[i].y;
        }
        return true;
    }
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            tot=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d %d",&a[i].x,&a[i].y);
                tot+=(a[i].x-a[i].y);
                a[i].y=(a[i].x-a[i].y);
            }
            sort(a,a+n);
            puts(cheak()?"Yes":"No");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Pandas绘图不支持中文解决方案
    MVC模式
    解决import javafx.geometry.Point2D无法导入的问题
    初学linux时遇到的那些哭笑不得的问题
    啊啊我找不到web.xml怎么办呀~~
    解决JSP调用JavaBean出现乱码问题
    设置eclipse自动补全
    ubuntu下eclipse java ee首次打开提示找不到jdk的问题
    android webview 报 [ERROR:in_process_view_renderer.cc(189)] Failed to request GL process. Deadlock likely: 0 问题
    ubuntu创建文件夹桌面快捷方式
  • 原文地址:https://www.cnblogs.com/clliff/p/4491467.html
Copyright © 2011-2022 走看看