zoukankan      html  css  js  c++  java
  • Dog Show CodeForces

    A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!

    On the show a dog needs to eat as many bowls of dog food as possible (bottomless stomach helps here). Dogs compete separately of each other and the rules are as follows:

    At the start of the show the dog and the bowls are located on a line. The dog starts at position x = 0 and n bowls are located at positions x = 1, x = 2, ..., x = n. The bowls are numbered from 1 to n from left to right. After the show starts the dog immediately begins to run to the right to the first bowl.

    The food inside bowls is not ready for eating at the start because it is too hot (dog's self-preservation instinct prevents eating). More formally, the dog can eat from the i-th bowl after ti seconds from the start of the show or later.

    It takes dog 1 second to move from the position x to the position x + 1. The dog is not allowed to move to the left, the dog runs only to the right with the constant speed 1 distance unit per second. When the dog reaches a bowl (say, the bowl i), the following cases are possible:

    • the food had cooled down (i.e. it passed at least ti seconds from the show start): the dog immediately eats the food and runs to the right without any stop,
    • the food is hot (i.e. it passed less than ti seconds from the show start): the dog has two options: to wait for the i-th bowl, eat the food and continue to run at the moment ti or to skip the i-th bowl and continue to run to the right without any stop.

    After T seconds from the start the show ends. If the dog reaches a bowl of food at moment T the dog can not eat it. The show stops before T seconds if the dog had run to the right of the last bowl.

    You need to help your dog create a strategy with which the maximum possible number of bowls of food will be eaten in T seconds.

    Input

    Two integer numbers are given in the first line - n and T (1 ≤ n ≤ 200 000, 1 ≤ T ≤ 2·109) — the number of bowls of food and the time when the dog is stopped.

    On the next line numbers t1, t2, ..., tn (1 ≤ ti ≤ 109) are given, where ti is the moment of time when the i-th bowl of food is ready for eating.

    Output

    Output a single integer — the maximum number of bowls of food the dog will be able to eat in T seconds.

    Example

    Input
    3 5
    1 5 3
    Output
    2
    Input
    1 2
    1
    Output
    1
    Input
    1 1
    1
    Output
    0

    Note

    In the first example the dog should skip the second bowl to eat from the two bowls (the first and the third).

    题解:很典型的贪心,能吃就吃,如果某处的等待时间大于当前所能得到的最大等待时间,就抛弃。在这个过程中更新答案。数据结构是亮点!!!!!!!!!!

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main()
     5 {   int n,T;
     6     cin>>n>>T;
     7     priority_queue<int> q;
     8     
     9     int ans=0;
    10     for(int i=1;i<=min(T-1,n);i++){
    11         while(!q.empty()&&q.top()>=T-i) q.pop();
    12         int x;
    13         scanf("%d",&x);
    14         if(x<T) q.push(x-i);
    15         ans=max(ans,(int)q.size());
    16     }
    17     printf("%d
    ",ans);
    18 }
  • 相关阅读:
    java程序后台报错java.net.SocketException: Too many open files
    linux中,查看某个命令是来自哪个RPM包或者是通过哪个RPM包安装的
    Oracle卸载之linux快速卸载rac脚本-一键卸载
    40个DBA日常维护的SQL脚本
    Oracle SQL开发 之 Select语句完整的执行顺序
    Oracle开发 之 主-外键约束FK及约束的修改
    drop user 报错ora-00604
    oracle Bug 4287115(ora-12083)
    Ora-1157 ora-1110错误解决案例一枚
    rac库grid目录权限(6751)导致数据库宕机案例 此方法仅用于紧急救助
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7673740.html
Copyright © 2011-2022 走看看