CF#257 (Div. 2) A.
来源:互联网 发布:淘宝女装级别最高 编辑:程序博客网 时间:2024/05/16 14:39
A. Jzzhu and Children
time limit per test
1 second
memory limit per test
256 megabytes
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:
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?
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.
解题思想:
又是CF上水题一道。大意是分糖果,n个孩子站成一排,每个孩子的a[ i ]代表期望得到的糖果数,但是每次只会给m个糖果,
若a[ i ] <= m的话,小孩就高兴的回家去了,否则a[ i ] - = m ,然后这个孩子站到队尾,求队伍里最后一个剩下的孩子是最初编号
为几的孩子。
开vis数组记录孩子们最开始的编号,然后从1到num开始遍历,注意遍历过程num是可以变化的,相当于开了一个可扩大长
度的数组。当孩子站到队尾时,记得要更新他的标号,即把原来的vis标记值赋给新的vis。
AC代码:
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>#include <string>#include <vector>#include <list>#include <map>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <numeric>#include <functional>using namespace std;#define REP(i, n) for (int i=0;i<int(n);++i)#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)#define REP_1(i, n) for (int i=1;i<=int(n);++i)#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)#define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)#define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)#define REP_N(i, n) for (i=0;i<int(n);++i)#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)#define REP_1_N(i, n) for (i=1;i<=int(n);++i)#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)#define REP_C_N(i, n) for (n____=int(n),i=0;i<n____;++i)#define FOR_C_N(i, a, b) for (b____=int(b),i=a;i<b____;++i)#define DWN_C_N(i, b, a) for (a____=int(a),i=b-1;i>=a____;--i)#define REP_1_C_N(i, n) for (n____=int(n),i=1;i<=n____;++i)#define FOR_1_C_N(i, a, b) for (b____=int(b),i=a;i<=b____;++i)#define DWN_1_C_N(i, b, a) for (a____=int(a),i=b;i>=a____;--i)#define Display(A, n, m) { \ REP(i, n){ \ REP(j, m) cout << A[i][j] << " "; \ cout << endl; \ } \}#define Display_1(A, n, m) { \ REP_1(i, n){ \ REP_1(j, m) cout << A[i][j] << " "; \ cout << endl; \ } \}typedef long long LL;typedef double DB;typedef unsigned UINT;typedef unsigned long long ULL;typedef vector<int> VI;typedef vector<char> VC;typedef vector<string> VS;typedef vector<LL> VL;typedef vector<DB> VD;typedef map<int, int> MII;typedef map<string, int> MSI;typedef map<LL, int> MLI;typedef map<DB, int> MDI;typedef pair<int, int> PII;typedef pair<int, bool> PIB;typedef pair<LL, LL> PLL;typedef vector<PII> VII;typedef vector<VI> VVI;typedef vector<VII> VVII;const int dx[] = {-1, 0, 1, 0};const int dy[] = {0, 1, 0, -1};const int MOD = 1000000007;const int INF = 0x3f3f3f3f;const LL INFF = 1LL << 60;const DB EPS = 1e-9;const DB OO = 1e15;const DB PI = acos(-1.0);int n , m , i;int a[1000010] , vis[1000010];int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif while(~scanf("%d%d",&n,&m)) { FOR_1(i , 1 , n) { scanf("%d",&a[i]); vis[i] = i; } int num = n; FOR_1(i , 1 , num) { if(i == num) { printf("%d\n",vis[i]); break; } if(a[i] <= m) continue; else { a[i] -= m; a[++num] = a[i]; vis[num] = vis[i]; } } }}
0 0
- CF#257 (Div. 2) A.
- cf 190div 2 A
- CF #230 (Div. 2) A
- CF#256 (Div. 2) A.
- CF#FF (Div. 2) A .
- CF#253 (Div. 2) A.
- CF#258 (Div. 2) A.
- CF#252 (Div. 2) A.
- CF#250 (Div. 2) A .
- CF#259 (Div. 2) A.
- CF #260 (Div. 2)A
- CF #261 (Div. 2) A
- CF#264 (Div. 2) A.
- CF #263 (Div. 2) A
- CF #266 (Div. 2) A.
- CF#267 (Div. 2) A
- CF#268 (Div. 2) A.
- CF#246 (Div. 2) A.
- 单例模式
- 277 车牌号
- 最近在用parse的时候遇到的BUG.A resource was acquired at attached stack trace but never released.
- HDU 1233 还是畅通工程(最小生成树入门)
- python 函数参数的传递(参数带星号的说明)
- CF#257 (Div. 2) A.
- VB.net之旅-SQLHelper的应用程序配置文件和使用(机房收费系统重构个人版)
- 苹果所有常用证书,appID,Provisioning Profiles配置说明及制作图文教程(精)
- 数的计数
- POJ 1458最长公共子序列(DP)
- 通过 ulimit 改善系统性能
- hihoCoder 1035 自驾旅行 树形DP
- Java集合源码学习(14)_BlockingQueue接口
- csdn夏令营week 1