CF div2 325 C
2015-10-13 00:40
183 查看
C. Gennady the Dentist
time limit per test
1 second
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
output
input
output
Note
In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.
In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5, - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
题目好长,都准备放弃看了的,结果仔细看了一遍发现就是个模拟。
View Code
time limit per test
1 second
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
Note
In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.
In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5, - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
题目好长,都准备放弃看了的,结果仔细看了一遍发现就是个模拟。
#include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <vector> #include <stack> using namespace std; const int M = 10005; const int maxn = 5000000; typedef long long ll; vector<int>G[maxn]; queue<int>Q; stack<int>st; struct node { int v,d,p,cnt; }a[maxn]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d%d%d",&a[i].v,&a[i].d,&a[i].p); a[i].cnt = 0; } queue<int>tt; for(int i=1;i<=n;i++){ if(a[i].cnt == 1) continue; int tm = a[i].v; for(int j=i+1;j<=n;j++){ if(tm <= 0) break; if(a[j].cnt == 1) continue; a[j].p -= tm; if(a[j].p<0){ tt.push(j); a[j].cnt = 1; } tm--; } while(!tt.empty()){ int t = tt.front(); tt.pop(); for(int i=t+1;i<=n;i++){ if(a[i].cnt == 1) continue; a[i].p -= a[t].d; if(a[i].p<0){ tt.push(i); a[i].cnt = 1; } } } } int ans = 0; for(int i=1;i<=n;i++){ if(a[i].cnt == 0) ans++; } printf("%d\n",ans); for(int i=1;i<=n;i++){ if(a[i].cnt == 0) printf("%d ",i); } return 0; }
View Code
相关文章推荐
- 冒泡排序算法小试[笑哭]
- poj3342 Party at Hali-Bula
- CF div2 325 B
- CF div2 325 A
- Linux使用错误小结(CentOS)- vim安装问题: Error: Nothing to do
- iOS 开发的9个超有用小技巧
- Android定制ListView的界面(使用继承自ArrayAdapter的自定义适配器)--《第一行代码Android》学习笔记
- Spring MVC4.2.1 xml配置
- 流媒体视频播放代码总结。
- VMware下扩展Ubuntu根分区大小的方法
- 工作-时间管理法
- Unity3D之FPS计算
- UIButton 按钮控件-IOS开发
- Appium环境配置
- C++基础---typedef struct与struct的区别
- UVA 11396 Claw Decomposition 染色
- 正则表达式(整理)
- O2O创业者醒醒吧!滴滴快的模式不可复制
- (中等) CF 585B Phillip and Trains,BFS。
- Ember.js 入门指南——处理事件