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 ------------------------------------------------ ...
随机推荐
- selenium定位失败记录
selenium webdriver定位不到元素的五种原因及解决办法 1.动态id定位不到元素 for example: //WebElement xiexin_element = driver.fi ...
- 【python cookbook】【数据结构与算法】20.将多个映射合并为单个映射
问题:在逻辑上将多个字典或映射合并为一个单独的映射结构,以此执行某些特定的操作,比如查找值或者检查键是否存在 解决方案:利用collections模块中的ChainMap类 ChainMap可接受多个 ...
- 161014、Comet4J介绍及使用(即时推送)
简介 Comet4J是一个微型的即时推送框架(类似于goeasy),它分为服务端与客户端两部分,你只要将服务器端(JAR文件,目前仅支持Tomcat6.7)放入WEB-INF\lib,客户端(Java ...
- linux中的优先搜索树的实现--prio_tree【转】
转自:http://blog.csdn.net/bailyzheng/article/details/8041943 linux中的优先搜索树的实现--prio_tree prio_tree在linu ...
- init_MUTEX 与 sema_init 函数【转】
转自:http://blog.chinaunix.net/uid-7332782-id-3211627.html 在编译Linux设备驱动程序学习(1)-字符设备驱动程序中scull.c程序时,报错: ...
- mybatis n+1问题
mybatis的一对多或者多对多的时候,2中方式解决,一种是嵌套select,但是会有n+1问题,不推荐:另外一种是使用一条sql,在该sql里面使用子查询的方式来完成.比如 select * fro ...
- Javascript Window Location
window.location 对象在编写时可不使用 window 这个前缀. URL : 统一资源定位符 (Uniform Resource Locator) 说明: 完整的URL示例:scheme ...
- Mysql 如何做双机热备和负载均衡
MySQL数据库没有增量备份的机制,但它提供了一种主从备份的机制,就是把主数据库的所有的数据同时写到备份数据库中.实现MySQL数据库的热备份. 下面是具体的主从热备份的步骤:假设主服务器A(mast ...
- 修改ECSHOP后台的商品列表里显示该商品品牌
如何在在ECSHOP后台的商品列表中也显示商品的品牌”.下面就来最模板讲一下如何来修改.此方法只保证在ECSHOP2.7.2版本下有效,其他版本请参照修改. 第一步:首先我们来打开程序文件: /adm ...
- 关闭用miniUI打开的窗口
miniUI打开的窗口用window.close关闭无效, 应该用window.CloseOwnerWindow();