Codeforces Problem - 37B - Computer Game (贪心、模拟)

B. Computer Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.

While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:

1) The boss has two parameters: max — the initial amount of health and reg — regeneration rate per second.

2) Every scroll also has two parameters: powi — spell power measured in percents — the maximal amount of health counted off the initial one, which allows to use the scroll (i.e. if the boss has more thanpowi percent of health the scroll cannot be used); and dmgi the damage per second inflicted upon the boss if the scroll is used. As soon as a scroll is used it disappears and another spell is cast upon the boss that inflicts dmgi of damage per second upon him until the end of the game.

During the battle the actions per second are performed in the following order: first the boss gets the damage from all the spells cast upon him, then he regenerates reg of health (at the same time he can’t have more than max of health), then the player may use another scroll (no more than one per second).

The boss is considered to be defeated if at the end of a second he has nonpositive ( ≤ 0) amount of health.

Help Petya to determine whether he can win with the set of scrolls available to him and if he can, determine the minimal number of seconds he needs to do it.

Input

The first line contains three integers Nmax and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 1001 ≤ dmgi ≤ 2000).

Output

In case Petya can’t complete this level, output in the single line NO.

Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the start of the battle to the moment the scroll was used and the number of the scroll. Scrolls are numbered starting from 1 in the input order. The first scroll is considered to be available to be used after 0 seconds.

Output scrolls in the order they were used. It is not allowed to use scrolls after the boss is defeated.

Examples
input
Copy
2 10 3
100 3
99 1
output
NO
input
Copy
2 100 10
100 11
90 9
output
YES
19 2
0 1
10 2

题意:

要用卷轴杀死一个血量为max,每秒回血量reg的怪兽

有n个卷轴,每个卷轴有各自的使用限制powi和持续每秒伤害dmgi,且卷轴伤害可叠加

第i个卷轴只能在怪物的血量小于等于初始血量的powi%时使用

每一秒只能使用一个卷轴,每秒的过程是先扣血,再回血,最后使用卷轴

判断是否可以用这n个卷轴杀死怪兽,若无法杀死输出NO,否则输出YES,并且输出它最短的死亡时间以及使用卷轴数量和每个卷轴使用时间将其按时间升序输出


要最快杀死,按卷轴伤害先排序,然后血量与卷轴数量较少,可以直接来遍历一下每一秒的情况,退出循环的条件就是怪兽血量为0或两次伤害不变且伤害低于怪兽回血量


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
using namespace std;
int n,x,y,t[1010],id[1010],vis[1010];
struct node{
    int id, p, d;
}a[1010];
bool cmp1(node a,node b){return a.d>b.d;}
bool cmp2(node a,node b){return a.id<b.id;}
int main()
{
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&a[i].p,&a[i].d);
        a[i].id = i;
    }
    sort(a+1,a+1+n,cmp1);
    int now = x, d = 0, be = 0, cnt = 0;
    for(int i=0; ; i++){
        now -= d; now += y;
        now = min(now, x);
        if(now<=0){
            printf("YES\n%d %d\n",i,cnt);
            for(int j=0;j<cnt;j++) printf("%d %d\n",t[j],id[j]);
            return 0;
        }
        for(int j=1;j<=n;j++){
            if(vis[j]||a[j].p*x<now*100) continue;
            vis[j] = 1; d += a[j].d;
            t[cnt] = i; id[cnt++] = a[j].id;
            break;
        }
        if(be==d&&d<=y) break;
        be = d;
    }
    printf("NO\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/w326159487/article/details/79753148