CodeForces#325 C. Gennady the Dentist
2015-10-13 11:31
281 查看
点击就送屠龙宝刀
memory limit per test 256 megabytes
input standard input
output standard output
Gennady is one of the best child dentists in Berland. Today n 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 1 to n in the order they go in the line. Every child is associated with the value of his cofidence 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 i-th child, the child is crying with the volume of vi. At that the confidence of the first child in the line is reduced by the amount of vi, the second one — by value vi - 1, and so on. The children in the queue after the vi-th child almost do not hear the crying, so their confidence remains unchanged.
If at any point in time the confidence of the j-th child is less than zero, he begins to cry with the volume of 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 j-th one in the line is reduced by the amount of 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.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 4000) — the number of kids in the line.
Next n lines contain three integers each vi, di, pi (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 i-th child.
Output
In the first line print number k — the number of children whose teeth Gennady will cure.
In the second line print k integers — the numbers of the children who will make it to the end of the line in the increasing order.
Sample test(s)
Input
5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2
Output
2
1 3
Input
5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9
Output
4
1 2 4 5
题目大意:有n个熊孩子去看医生,每个人都有一个pi(信心值)、一个vi(声音影响度)、一个di(影响值)。当一个熊孩子接受治疗时,会发出vi的影响,影响后面vi个单位,分别为vi-1,vi-2,vi-3……0.当某个人的信心值pi小于0时,他就吓尿了于是就跑掉了,同时对后面所有人造成di的影响。(注:造成x的影响意思为pi-x)。你的任务就是统计有多少个熊孩子看了医生,并且按照顺序输出他们的编号。
模拟大法好233333毕竟只有4000的范围
C. Gennady the Dentist
time limit per test 1 secondmemory limit per test 256 megabytes
input standard input
output standard output
Gennady is one of the best child dentists in Berland. Today n 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 1 to n in the order they go in the line. Every child is associated with the value of his cofidence 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 i-th child, the child is crying with the volume of vi. At that the confidence of the first child in the line is reduced by the amount of vi, the second one — by value vi - 1, and so on. The children in the queue after the vi-th child almost do not hear the crying, so their confidence remains unchanged.
If at any point in time the confidence of the j-th child is less than zero, he begins to cry with the volume of 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 j-th one in the line is reduced by the amount of 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.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 4000) — the number of kids in the line.
Next n lines contain three integers each vi, di, pi (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 i-th child.
Output
In the first line print number k — the number of children whose teeth Gennady will cure.
In the second line print k integers — the numbers of the children who will make it to the end of the line in the increasing order.
Sample test(s)
Input
5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2
Output
2
1 3
Input
5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9
Output
4
1 2 4 5
题目大意:有n个熊孩子去看医生,每个人都有一个pi(信心值)、一个vi(声音影响度)、一个di(影响值)。当一个熊孩子接受治疗时,会发出vi的影响,影响后面vi个单位,分别为vi-1,vi-2,vi-3……0.当某个人的信心值pi小于0时,他就吓尿了于是就跑掉了,同时对后面所有人造成di的影响。(注:造成x的影响意思为pi-x)。你的任务就是统计有多少个熊孩子看了医生,并且按照顺序输出他们的编号。
模拟大法好233333毕竟只有4000的范围
#include<iostream> #include<cstdio> #include<vector> using namespace std; const int maxn = 5500; int v[maxn],p[maxn],d[maxn]; int main() { int n,ans=0; scanf("%d",&n); vector<int> Q; for(int i=1;i<=n;i++) { scanf("%d%d%d",&v[i],&d[i],&p[i]); } for(int i=1;i<=n;i++) { if(p[i]>=0) { ans++; Q.push_back(i); for(int j=v[i]-1;j>0;j--) { p[i+v[i]-j]-=j; } } if(p[i]<0) { for(int j=i-1;j<=n;j++) p[j]-=d[i]; } } cout<<ans<<endl; for(int i=0;i<Q.size();i++) cout<<Q[i]<<" "; }
相关文章推荐
- 关于Java函数传参以及参数在函数内部改变的问题——JAVA值传递与引用最浅显的说明!...
- DELPHI如何获取某目录下的所有文件名?
- 请把Camera hold住 - Android高通平台调试Camera驱动全纪录
- 【解决方法】iOS9 HTTP 不能正常使用的解决办法(数据无法加载)
- 关于Java函数传参以及参数在函数内部改变的问题——JAVA值传递与引用最浅显的说明!
- 4种方法解决后台接受前台中文信息乱码的问题
- MySql查询结果按照指定顺序排序
- C#的事件处理机制
- AngularJS中$http服务的简单用法
- C++中四种类型转换方式
- 对假货指责马云坐不住了:伤阿里有限,伤中国制造是根本
- Hadoop远程过程调用
- ImageLoader异步加载图片框架浅谈
- Unity3d之MonoBehaviour的可重写函数整理
- Oracle中group by用法
- linux umount 提示device is busy 的解决
- 问题:c# json解析;结果:c# 解析JSON的几种办法
- ASP.Net MVC开发基础学习笔记(1):走向MVC模式
- kafka
- VBA如何获取当前EXCEL文件的路径