Codeforces 586C Gennady the Dentist【模拟】

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 from1 to n in the order they go in the line. Every child is associated with the value of hiscofidence 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 ofvi. At that theconfidence of the first child in the line is reduced by the amount ofvi, the second one — by valuevi - 1, and so on. The children in the queue after thevi-th child almost do not hear the crying, so theirconfidence remains unchanged.

If at any point in time the confidence of thej-th child is less than zero, he begins to cry with the volume ofdj and leaves the line, running towards the exit, without going to the doctor's office. At this theconfidence 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 eachvi, 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 theconfidence 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.

Examples
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 volume4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of1 and run to the exit. The confidence of the remaining children will be equal to0, 2, 0. Then the third child will go to the office, and cry with volume5. 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 volume4. The confidence of the remaining children will be equal to5,  - 1, 6, 8. Thus, the third child will cry with the volume of1 and run to the exit. The confidence of the remaining children will be equal to5, 5, 7. After that, the second child goes to the office and cry with the volume of5. The confidences of the remaining children will be equal to0, 3. Then the fourth child will go into the office and cry with the volume of2. Because of this the confidence of the fifth child will be1, and he will go into the office last.


题目大意:

现在有N个小孩在排队看医生,每个人有三个元素:v,d,p。其中p代表每个小孩的勇气值,如果勇气值小于0的时候,这个小孩就会逃跑,并且对其身后所有的小孩的勇气值造成d的伤害值。

小孩按照顺序进入医疗室,当进入的时候,他一共会哭出来V单位的眼泪,后边的小孩会受到影响,他身后第一个小孩的勇气值会减少v,第二个小孩的勇气值会减少v-1.第三个小孩的勇气值会减少v-2.当按照这个规律到v-v的时候,之后的小孩就不会受影响。

问哪些小孩会成功的被医疗。


思路:


因为N并不大,所以我们O(n^2)模拟即可。

不过注意一点,在模拟过程中,一定要按照情景进行模拟,其中有一些限制顺序存在互相影响的关系。


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
#define ll __int64
struct node
{
    ll v,d,p;
}a[5000];
int vis[5000];
int ans[5000];
int n;
void Slove(int pos)
{
    vis[pos]=1;
    for(int i=pos+1;i<n;i++)
    {
        if(vis[i]==1)continue;
        a[i].p-=a[pos].d;
    }
    for(int i=pos+1;i<n;i++)
    {
        if(vis[i]==0&&a[i].p<0)Slove(i);
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
        {
            scanf("%I64d%I64d%I64d",&a[i].v,&a[i].d,&a[i].p);
        }
        int cont=0;
        for(int i=0;i<n;i++)
        {
            if(vis[i]==1)continue;
            if(a[i].p>=0)
            {
                ans[cont++]=i+1;
                for(int j=i+1;j<n;j++)
                {
                    if(vis[j]==1)continue;
                    if(a[i].v>0)
                    {
                        a[j].p-=a[i].v;
                        a[i].v-=1;
                    }
                }
                for(int j=i+1;j<n;j++)
                {
                    if(a[j].p<0&&vis[j]==0)
                    {
                        Slove(j);
                    }
                }
            }
            else Slove(i);
        }
        printf("%d\n",cont);
        for(int i=0;i<cont;i++)printf("%d ",ans[i]);
        printf("\n");
    }
}



关于Codeforces上的问题'Trail',目前提供的参考资料中并未直接提及该问题的具体解法或讨论[^1]。然而,在处理类似平台上的编程挑战时,通常会遵循特定的方法论来解决问题。 对于未具体描述的问题'Trail',假设这是一个涉及路径遍历或是图结构中的轨迹计算等问题,一般解决方案可能涉及到深度优先搜索(DFS)、广度优先搜索(BFS)或者是动态规划等技术。这些方法能够有效地探索所有可能性并找到最优解。 考虑到Codeforces平台上许多问题的特点,解决这类题目往往还需要注意边界条件以及输入数据范围的影响。编写代码前应仔细阅读题目说明,确保理解所有的约束条件和特殊案例。 下面是一个简单的Python实现例子,用于展示如何通过深度优先搜索算法在一个假定的网格环境中寻找从起点到终点的有效路径: ```python def dfs(grid, start, end): rows, cols = len(grid), len(grid[0]) visited = set() def explore(r, c): if (r < 0 or r >= rows or c < 0 or c >= cols or grid[r][c] == '#' or (r,c) in visited): return False if (r, c) == end: return True visited.add((r, c)) directions = [(0, 1), (1, 0), (-1, 0), (0, -1)] for dr, dc in directions: next_r, next_c = r + dr, c + dc if explore(next_r, next_c): return True return False return explore(*start) # Example usage with a simple maze represented as a list of strings. maze = [ '..#.##', '#...#.', '#####.' ] print(dfs(maze, (0, 0), (2, 5))) # Output should be True based on this example layout. ``` 此段代码展示了利用递归方式执行深度优先搜索的过程,适用于某些类型的‘Trail’类问题。当然实际应用中还需根据具体的题目要求调整逻辑细节。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值