Who Gets the Most Candies?

Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 262144/131072K (Java/Other)
Total Submission(s) : 15   Accepted Submission(s) : 7
Problem Description

N children are sitting in a circle to play a game.

The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from the K-th child, who tells all the others the integer on his card and jumps out of the circle. The integer on his card tells the next child to jump out. Let A denote the integer. If A is positive, the next child will be the A-th child to the left. If A is negative, the next child will be the (−A)-th child to the right.

The game lasts until all children have jumped out of the circle. During the game, the p-th child jumping out will get F(p) candies where F(p) is the number of positive integers that perfectly divide p. Who gets the most candies?

 
Input
There are several test cases in the input. Each test case starts with two integers N (0 < N ≤ 500,000) and K (1 ≤ KN) on the first line. The next N lines contains the names of the children (consisting of at most 10 letters) and the integers (non-zero with magnitudes within 108) on their cards in increasing order of the children’s numbers, a name and an integer separated by a single space in a line with no leading or trailing spaces.
 
Output

Output one line for each test case containing the name of the luckiest child and the number of candies he/she gets. If ties occur, always choose the child who jumps out of the circle first.

 
Sample Input
4 2
Tom 2
Jack 4
Mary -1
Sam 1
 
Sample Output
Sam 3
/*题意:N个人围成一圈第一个人跳出圈后会告诉你下一个谁跳出来跳出来的人
(如果他手上拿的数为正数,从他左边数A个,反之,从他右边数A个)
跳出来的人所得到的糖果数量和他跳出的顺序有关 所得的糖果数为 (假设他是第k个跳出的) 则他得到的糖数为k能被多少个数正数
比如说 k = 6 ; 6 = 1*2*3*6 所以他得到的糖数为4; 思路:线段数 先算出N个人中,是第几个人(id)跳出来得到的糖果最多。然后模拟id遍 长到第id个人的name
线段树的结点中保存该区间内还剩多少人,每次update 删除一个人。*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#define maxn 500004
int n,id;
struct node
{
int left,right;
int num;
};
node tree[*maxn];
struct data
{
int val;
char name[];
} boy[maxn]; int ans[maxn];
void build(int left,int right,int i)
{
tree[i].left =left;
tree[i].right =right;
tree[i].num =right-left+;
if(tree[i].left ==tree[i].right )
return ;
build(left,(left+right)/,*i);
build((left+right)/+,right,*i+);
}
int insert(int i,int x)
{
tree[i].num--;
if(tree[i].left==tree[i].right)
return tree[i].left;
if(x<=tree[i].num)
return insert(*i,x);
else
return insert(*i+,x-tree[*i].num);
}
void count_ans()//这个函数最重要。
{
int i,max,j;
memset (ans,,sizeof(ans)); //计算ans
for (i = ; i <= n; i ++)
{
ans[i] ++;
for (j=*i;j<= n;j+= i)
ans[j] ++;
}
max = ans[];
id = ;
for (i = ; i <= n; i ++) //找出第几个人跳出获得的糖最多
if (ans[i] > max)
{
max = ans[i];
id = i;
}
}
int main ()
{
int i,k,mod;
while (~scanf ("%d %d",&n,&k))
{
count_ans();
for (i = ; i <= n; i ++)
scanf ("%s %d",boy[i].name,&boy[i].val);
build(,n,);
mod =tree[].num;
int pos = ;
boy[].val = ;
n = id;
while (n --)
{
if (boy[pos].val > ) //k表剩余的人中从左起第k中出队(PS:k的求法是看别人的)
k = ((k + boy[pos].val - )%mod + mod)%mod + ;
else
k = ((k + boy[pos].val - )%mod + mod)%mod + ;
pos = insert(,k);
mod = tree[].num;
}
printf ("%s %d\n",boy[pos].name,ans[id]);
}
return ;
}

HDU- Who Gets the Most Candies?的更多相关文章

  1. 【HDU 6126】Give out candies 最小割

    题意 有$n​$个小朋友,给每个人分$1~m​$个糖果,有k个限制 限制形如$(x,y,z)​$ 表示第$x​$个人分到的糖数减去第$y​$个人分到的糖数不大于$z​$,给第$i​$个人$j​$颗糖获 ...

  2. HDU 6126.Give out candies 最小割

    Give out candies Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

  3. hdu 6126 Give out candies

    hdu 6126 Give out candies(最小割) 题意: 有\(n\)个小朋友,标号为\(1\)到\(n\),你要给每个小朋友至少\(1\)个且至多\(m\)个的糖果.小朋友们共提出\(k ...

  4. Hdu 5407 CRB and Candies (找规律)

    题目链接: Hdu 5407 CRB and Candies 题目描述: 给出一个数n,求lcm(C(n,0),C[n,1],C[n-2]......C[n][n-2],C[n][n-1],C[n][ ...

  5. HDU 6085 - Rikka with Candies | 2017 Multi-University Training Contest 5

    看了标程的压位,才知道压位也能很容易写- - /* HDU 6085 - Rikka with Candies [ 压位 ] | 2017 Multi-University Training Cont ...

  6. HDU 5127 Dogs' Candies

    Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) T ...

  7. 2017ACM暑期多校联合训练 - Team 5 1001 HDU 6085 Rikka with Candies (模拟)

    题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...

  8. HDU 6085 Rikka with Candies(bitset)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6085 [题目大意] 给出一个数组a一个数组b,以及询问数组c, 问对于每个c有多少对a%b=c,答 ...

  9. 2017多校第5场 HDU 6085 Rikka with Candies bitset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6085 题意:存在两个长度为n,m的数组A,B.有q个询问,每个询问有一个数字k,可以得到Ai%Bj=k ...

  10. HDU 5407(2015多校10)-CRB and Candies(组合数最小公倍数+乘法逆元)

    题目地址:pid=5407">HDU 5407 题意:CRB有n颗不同的糖果,如今他要吃掉k颗(0<=k<=n),问k取0~n的方案数的最小公倍数是多少. 思路:首先做这道 ...

随机推荐

  1. 页面资源预加载(Link prefetch)功能加速你的页面加载速度

    有了浏览器缓存,为何还需要预加载? 用户可能是第一次访问网站,此时还无缓存 用户可能清空了缓存 缓存可能已经过期,资源将重新加载 用户访问的缓存文件可能不是最新的,需要重新加载 页面资源预加载/预读取 ...

  2. P1396 营救

    P1396 营救 218 通过 571 提交 题目提供者yeszy 标签 二分 图论 并查集 福建省历届夏令营 难度 普及- 题目描述 "咚咚咚--""查水表!" ...

  3. (转)IOS内存管理 retain release

    obj-c本质就是"改进过的c语言",大家都知道c语言是没有垃圾回收(GC)机制的(注:虽然obj-c2.0后来增加了GC功能,但是在iphone上不能用,因此对于iOS平台的程序 ...

  4. ASP.NET中Json的处理

    要使用.NET自带的JSON处理工具需要引用下面的命名空间: using System.Web.Script.Serialization; 1.编码 myConfig mc = new myConfi ...

  5. PHP 文字,图片水印,缩略图,裁切成小图(大小变小)

    文字水印基本思路:1.用getimagesize()获取图片的信息(as:大小,属性等):2.根据图片信息用imagecreatefromjpeg ()/imagecreatefromgif/imag ...

  6. C# Linq To DataTable 分组统计 DEMO

    DataTable dt = SQLLayer.Get工作量统计(beginDate, endDate);             var querySum = from t in dt.AsEnum ...

  7. PHP PhantomJs中文文档(翻译)

    介绍 PHP PhantomJS 是一个灵活的 PHP 库加载页面通过 PhantomJS 无头浏览器并将返回页面响应.这是方便于需要JavaScript的支持,同时还支持截屏测试网站.功能列表通过 ...

  8. php中getimagesize函数的用法

    php获取图片信息getimagesize,php自带函数.获取图片的类型,尺寸的方法有许多,该函数仅是方法之一. getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC ...

  9. 精通 Oracle+Python,第 1 部分:查询最佳应践

    原文链接:http://www.oracle.com/technetwork/cn/articles/dsl/mastering-oracle-python-1391323-zhs.html 在 Py ...

  10. JVM 找出最耗 cpu的线程 并打印线程栈

    监控JVM中最占cpu的线程 top -Hp pid JVM中最占cpu的线程ID -o THREAD,tid,time | awk 'BEGIN {count=0; } { if($2>0.3 ...