A. Gennady the Dentist

https://codeforces.com/problemset/problem/585/A


 

题目描述

Gennady is one of the best child dentists in Berland. Today nn children got an appointment with him, they lined up in front of his office.

All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 11 to nn in the order they go in the line. Every child is associated with the value of his cofidence p_{i}pi​ . The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.

While Gennady treats the teeth of the ii -th child, the child is crying with the volume of v_{i}vi​ . At that the confidence of the first child in the line is reduced by the amount of v_{i}vi​ , the second one — by value v_{i}-1vi​−1 , and so on. The children in the queue after the v_{i}vi​ -th child almost do not hear the crying, so their confidence remains unchanged.

If at any point in time the confidence of the jj -th child is less than zero, he begins to cry with the volume of d_{j}dj​ and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the jj -th one in the line is reduced by the amount of d_{j}dj​ .

All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.

Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.

输入格式

The first line of the input contains a positive integer nn ( 1<=n<=40001<=n<=4000 ) — the number of kids in the line.

Next nn lines contain three integers each v_{i},d_{i},p_{i}vi​,di​,pi​ ( 1<=v_{i},d_{i},p_{i}<=10^{6}1<=vi​,di​,pi​<=106 ) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the ii -th child.

输出格式

In the first line print number kk — the number of children whose teeth Gennady will cure.

In the second line print kk integers — the numbers of the children who will make it to the end of the line in the increasing order.

题意翻译

Description 一个医生给n个孩子拔牙,每个孩子有一个哭时的分贝大小v,哭声对其他孩子的影响数d以及自信度p,每当一个孩子拔牙之后,他的哭声会使其他的孩子失去信心,初始值为v,每经过一个人减少v-1,直至vi为0,如果其中有一个孩子的信心为负那么他会不拔牙跑了,他后面孩子的信心度都减去这个孩子的d值,问这个医生能给几个孩子拔牙,输出他们的编号。 Input 第一行为一整数n表示孩子数,之后n行每行三个整数v,d,p表示孩子的三个特点值。 Output 输出这个拔牙的孩子数以及这些孩子的编号。

输入输出样例

输入 #1复制

5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2

输出 #1复制

2
1 3 

输入 #2复制

5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9

输出 #2复制

4
1 2 4 5 

思路:模拟,用vis[]判小孩还在不在队列中。

坑点:

1.要等哭声都减完了再开始跑

2.long long

3.注意题目是小孩子跑出去只对后面的小孩子有影响,不是整个队里的小孩子有影响。

剩余看代码:

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=4e3+100;
typedef long long LL;
struct child{
  LL v,d,p;
}a[maxn];
LL b[maxn];
bool vis[maxn];
LL n;
void influence2(LL run,LL pos)
{
	for(LL i=pos;i<=n;i++)
	{
		if(vis[i]==1)
		{
		    a[i].p-=run;
		}
	}
}
void influence1(LL cry)
{
	for(LL i=1;i<=n;i++)
	{
		if(vis[i]==1&&cry>=0)
		{
			a[i].p-=cry;cry--;
		}
	}
	for(LL i=1;i<=n;i++)
	{
		if(vis[i]==1&&a[i].p<0)
		{
			vis[i]=0;
			influence2(a[i].d,i);
		}
	}
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  cin>>n;
  for(LL i=1;i<=n;i++)
  {
  	cin>>a[i].v>>a[i].d>>a[i].p;
  }
  memset(vis,1,sizeof(vis));
  LL cnt=0;
  for(LL i=1;i<=n;i++)
  {
  	if(vis[i]==1)
  	{
  		vis[i]=0;b[++cnt]=i;
		influence1(a[i].v);  
	}
  }
  cout<<cnt<<endl;
  for(LL i=1;i<=cnt;i++) cout<<b[i]<<" ";
  cout<<endl;
return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值