Codeforces Round #257 (Div. 2) A. Jzzhu and Children
来源:互联网 发布:模拟汽车软件 国外 编辑:程序博客网 时间:2024/06/05 18:12
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from1 to n. The i-th child wants to get at least ai candies.
Jzzhu asks children to line up. Initially, the i-th child stands at thei-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
- Give m candies to the first child of the line.
- If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
- Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers n, m(1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line containsn integers a1, a2, ..., an(1 ≤ ai ≤ 100).
Output a single integer, representing the number of the last child.
5 21 3 1 4 2
4
6 41 1 2 2 3 3
6
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home.
题意:n个孩子依次给m个糖果,求最后一个得到满足的孩子的编号。
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <cstring>#include <stdlib.h>using namespace std;int a[110];int l[110];int b[110];int main(){ int n,m; scanf("%d%d",&n,&m); memset(l,0,sizeof l); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); b[i]=a[i]; } int j=0; sort(b+1,b+n+1); int temp=b[n]/m+1; while(temp--){ for(int i=1;i<=n;i++){ if(a[i]>0&&m>=a[i]){ l[j++]=i; a[i]-=m; } else{ a[i]-=m; } if(j==n) break; } if(j==n) break; } printf("%d",l[n-1]); return 0;}
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
- Codeforces Round #257 (Div. 2)1A Jzzhu and Children
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
- Codeforces Round #257 (Div. 2)A. Jzzhu and Children
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
- Codeforces Round #257 (Div. 2) Jzzhu and Children (队列)
- Codeforces Round #257 (Div. 2) 450A - Jzzhu and Children(模拟)
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children解题报告
- Codeforces Div. 2 #257-A. Jzzhu and Children
- Codeforces #257 div 2 A. Jzzhu and Children
- Codeforces Round #257 (Div. 2)449A - Jzzhu and Chocolate
- Codeforces Round #257 (Div. 2/A)/Codeforces450A_Jzzhu and Children
- cf #257(Div.2) A. Jzzhu and Children
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Twitter,Facebook和社交媒体 - 对非结构化数据分析
- hdu 1864最大报销额 (01背包模板)
- HDU 4864 Task
- 关于会计科目表,科目组,字段状态组
- Spring 注解学习(三) 表单页面处理
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
- jQuery 的选择器总结
- Java异常处理问题
- CGImageRef转换成UIImage
- AFNetworking 的使用
- 小米开源
- java getDeclaredField
- Twitter的介绍了网站分析工具
- jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class