[ An Ac a Day ^_^ ] CodeForces 586C Gennady the Dentist 模拟

时间:2023-03-09 08:49:13
[ An Ac a Day ^_^ ] CodeForces 586C Gennady the Dentist 模拟

题意:

n个小朋友去拔牙 每个小朋友在拔牙的时候会哭 哭声是vi分贝

距离门口vi远的小朋友听到了哭声会害怕 他们的勇气值p会减少d

如果勇气值p小于等于零 他们就会在门外哭并立即离开拔牙队列(回家找妈妈……)

这个哭声门外所有的小朋友都能听到 所以这个哭声会同时减少所有小朋友的勇气值

问最后有多少小朋友可以拔完牙

思路:

就是模拟一下这个过程

好像后面的小朋友哭了对前面的小朋友没有影响

WA了一次是因为结构体里没用long long……

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
struct child{
ll vi,d,p;
}child[];
int cnt=,ans[];
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d%I64d%I64d",&child[i].vi,&child[i].d,&child[i].p);
for(int i=;i<=n;i++){
if(child[i].p<) continue;
ans[cnt++]=i;
ll v=child[i].vi,cry=;
for(int j=i+;j<=n;j++){
if(child[j].p<) continue;
child[j].p-=v+cry;
v--;
if(v<) v=;
if(child[j].p<) cry+=child[j].d;
}
}
printf("%d\n",cnt);
for(int i=;i<cnt;i++)
printf("%d%c",ans[i],i==cnt-?'\n':' ');
return ;
}
/* 5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2 5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9 */