zoukankan      html  css  js  c++  java
  • Codeforces Testing Round #12 B. Restaurant 贪心

    B. Restaurant

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/597/problem/B

    Description

    A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).

    Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?

    No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.


    ⋅2. Ignoring the buoys and relying on dogfighting to get point. If you and your opponent meet in the same position, you can try to fight with your opponent to score one point. For the proposal of game balance, two players are not allowed to fight before buoy #2 is touched by anybody.

    There are three types of players.

    Speeder: As a player specializing in high speed movement, he/she tries to avoid dogfighting while attempting to gain points by touching buoys.
    Fighter: As a player specializing in dogfighting, he/she always tries to fight with the opponent to score points. Since a fighter is slower than a speeder, it's difficult for him/her to score points by touching buoys when the opponent is a speeder.
    All-Rounder: A balanced player between Fighter and Speeder.

    There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
    Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

    Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting. Since Asuka is slower than Shion, she decides to fight with Shion for only one time during the match. It is also assumed that if Asuka and Shion touch the buoy in the same time, the point will be given to Asuka and Asuka could also fight with Shion at the buoy. We assume that in such scenario, the dogfighting must happen after the buoy is touched by Asuka or Shion.

    The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

    Input

    The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

    Output

    Print the maximal number of orders that can be accepted.

    Sample Input

    6
    4 8
    1 5
    4 7
    2 5
    1 3
    6 8

    Sample Output

    2

    HINT

    题意

    给你n个区间,然后让你选择尽量多的不同区间出来

    让你输出数量

    题解:

    按照右坐标排序,然后贪心扫一遍就好了~

    代码

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    #define maxn 500005
    struct node
    {
        int l,r;
    };
    bool cmp(node a,node b)
    {
        if(a.r==b.r)return a.l<b.l;
        return a.r<b.r;
    }
    node p[maxn];
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d%d",&p[i].l,&p[i].r);
        sort(p,p+n,cmp);
        int ans = 0;
        int last = -1;
        for(int i=0;i<n;i++)
        {
            if(p[i].l>last)
            {
                ans++;
                last = p[i].r;
            }
        }
        printf("%d
    ",ans);
    }
  • 相关阅读:
    查找mysql数据库中所有包含特定名字的字段所在的表
    redis在windows下安装和PHP中使用
    CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境
    telnet: connect to address 127.0.0.1: Connection refused
    [Java]局域网五子棋
    springboot-web进阶(三)——统一异常处理
    springboot-web进阶(二)——AOP统一处理请求
    springboot-web进阶(一)——表单验证
    springboot快速入门(五)——事务管理
    springboot快速入门(四)——数据库操作
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4960070.html
Copyright © 2011-2022 走看看