Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

题目链接:http://codeforces.com/problemset/problem/450/A

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

A. Jzzhu and Children

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n children in Jzzhu‘s school. Jzzhu is going to give some candies to them. Let‘s number all the children from 1 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 the i-th
place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:

  1. Give m candies to the first child of the line.
  2. If this child still haven‘t got enough candies, then the child goes to the end of the line, else the child go home.
  3. 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?

Input

The first line contains two integers n,?m (1?≤?n?≤?100; 1?≤?m?≤?100).
The second line contains n integers a1,?a2,?...,?an (1?≤?ai?≤?100).

Output

Output a single integer, representing the number of the last child.

Sample test(s)

input

5 2
1 3 1 4 2

output

4

input

6 4
1 1 2 2 3 3

output

6

Note

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.

代码如下:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

struct child
{
	int x,num;
}a[1000017];
int main()
{
	int i, j, k;
	int n, m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(a,0,sizeof(a));
		for(i = 1; i <= n; i++)
		{
			scanf("%d",&a[i].x);
			a[i].num = i;
		}
		int l = n;
		for(i = 1; a[i].x != 0; i++)
		{
			if(a[i].x <= m)
			{
				a[i].x = 0;
				continue;
			}
			if(a[i].x > m)
			{
				l++;
				a[l].x = a[i].x-m;
				a[l].num = a[i].num;
				a[i].x = 0;
			}
		}
		printf("%d\n",a[i-1].num);
	}
	return 0;
}
时间: 2024-10-07 05:46:14

Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)的相关文章

Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA

题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路的权值大于该点最短距离的显然可以删去,否则将该条边加入图中,再求最短路,记录每个点的前一个点,然后又枚举铁路,已经删去的就不用处理了,如果铁路权值大于该点最短距离又可以删去,权值相等时,该点的前一个点如果不为1,则这个点可以由其他路到达,这条铁路又可以删去. 由于本题中边比较多,最多可以有8x10^

Codeforces Round #257 (Div. 2/A)/Codeforces450A_Jzzhu and Children

解题报告 没什么好说的,大于m的往后面放,,,re了一次,,, #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; struct node { int x,cd; }num[1000000]; int main() { int n,m,c; cin>>n>>m; int i; for(i=0;i&l

Codeforces Round #257 (Div. 2)449A - Jzzhu and Chocolate(贪心、数学)

题目链接:http://codeforces.com/problemset/problem/449/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)

题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. 1 /* 2 | 1, -1 | | fn | 3 | 1, 0 | | fn-1 | 4 */ 5 #include <iostream> 6 #include <cstdio> 7 #include <cstring> 8 using namespace std; 9 typedef __int64 LL; 10 LL mod =

Codeforces Round #257 (Div. 2) B Jzzhu and Sequences

Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109?+?7). Input The first line contains two integers x and y (|x|,?|y|?≤?109). The second line contains a single i

Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp

D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] 需要用SOSdp #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities【最短路】

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities[最短路] 题目链接:点击打开 题目大意: 在一个国家中有n个城市(城市编号1~n),m条公路和k条铁路,编号为1的城市为首都,为了节约,不需要的铁路需要关闭,问在保证首都到其余所有城市的最短路不变的条件下,最多有多少条铁路是不需要的. 解法: 这个题比较麻烦,保证首都到其余城市的最短路不变,要求出最多有多少条铁路是不需要的,那肯定是从最短路的代码上下手了,我们首先考虑dijkstra算法

Codeforces Round #257 (Div. 2)

A.Jzzhu and Children 计算每个人会出现的轮次数,取最后一个且轮次数最大的,注意是用a[i]-1 % m,倒着扫一遍就行了 #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; const int maxn = 100+10; int n, m; int a[maxn]; int main() { #ifdef LOCAL freopen("