Codeforces Round #257 (Div. 2) A题
1 second
256 megabytes
standard input
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 1to 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?
The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains n integersa1, a2, ..., an (1 ≤ ai ≤ 100).
Output a single integer, representing the number of the last child.
5 2
1 3 1 4 2
4
6 4
1 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.
---------------------------------------------------
题目意思是给几个孩子发糖,每个孩子都有自己要的糖的个数,但是每次只是固定的发一定量的糖,每个没拿到自己期望的糖数就到队尾继续排队,问你最后走的孩子是几号
、、、、、、、、、、、、、、、、、、、、、、、、、、
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm> using namespace std; int main()
{
int n,m,i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
int str[],maxx=,st;
for(i=;i<n;i++)
{
scanf("%d",&str[i]);
if(maxx<str[i])
{
maxx=str[i];
}
}
st=maxx/m;
if(st*m<maxx)
{
st++;
}//printf("%d%d**",st,maxx);
for(i=;i<n;i++)
{
str[i]-=(st-)*m;//printf("%d**",str[i]);
}
int res=,cas;
for(i=;i<n;i++)
{
if(str[i]>)
{
//res=str[i];
cas=i;
}
}
printf("%d\n",cas+);
}
return ;
}
这是队列模拟的
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue> using namespace std; typedef struct stu
{
int id,m;
}stu;
stu str[]; int main()
{
int i,j,n,m,k,t; while(scanf("%d%d",&n,&m)!=EOF)
{
queue<stu >q; for(i=;i<n;i++)
{
scanf("%d",&str[i].m);
str[i].id=i+;
q.push(str[i]);
}
int tmp=;
while(!q.empty())
{
stu x=q.front();
q.pop();
if(x.m<=m)
{
tmp=x.id;
}
else
{
x.m-=m;
q.push(x);
}
}
printf("%d\n",tmp);
}
return ;
}
这题A题卡了我好久,主要因为数组模拟没有想到找最大的那个趟数来模拟
经验不足……
Codeforces Round #257 (Div. 2) A题的更多相关文章
- Codeforces Round #257 (Div. 2) D题:Jzzhu and Cities 删特殊边的最短路
D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...
随机推荐
- V4L2驱动程序框架架构【转】
本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11728809 1 V4L2简介 video4linux2(V4L2)是Linux内核中关 ...
- 【secureCRT】设置自动连接会话+设置自动连接上次使用的会话:
- 160921、React入门教程第一课--从零开始构建项目
工欲善其事必先利其器,现在的node环境下,有太多好用的工具能够帮助我们更好的开发和维护管理项目. 我本人不建议什么功能都自己写,我比较喜欢代码复用.只要能找到npm包来实现的功能,坚决不自己敲代码. ...
- Asp.Net Mvc视图引擎Razor介绍
1.Razor介绍 1)ASP.NET MVC3 带来了一种新的名为Razor 的视图引擎,提供了下列优点: Razor 的语法简单且清晰,只需要最小化的输入 Razor 容易学习,语法类似于 C# ...
- 【转载】Perl异常处理方法总结
程序脚本在运行过程中,总会碰到这样那样的问题,我们会预知一些问题并为其准备好处理代码,而有一些不能预知.好的程序要能尽可能多的处理可能出现的异常问题,本文就总结了一些方法来解决这些异常,当然perl在 ...
- paste DEMO合并文件
测试数据: [xiluhua@vm-xiluhua][~]$ cat msn.txt aaa bbb bbb ccc ccc ddd bbb eee aaa ccc bbb sss [xiluhua@ ...
- PHP删除MySQL数据库下的所有数据表
<?php //[数据无价,请谨慎操作!] $hostname ='localhost'; $userid = 'username'; $password = 'password'; $d ...
- 【转】Eclipse Console 加大显示的行数,禁止弹出
转载地址:http://blog.csdn.net/leidengyan/article/details/5686691 Eclipse Console 加大显示的行数: 在 Preferences- ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
- 【20160924】GOCVHelper 图像增强部分(1)
图像增强是图像处理的第一步.这里集成了一些实际使用过程中有用的函数. //读取灰度或彩色图片到灰度 Mat imread2gray(string path){ Mat sr ...