博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2886 Who Gets the Most Candies?(线段树单点更新+反素数)真难。。。
阅读量:4035 次
发布时间:2019-05-24

本文共 3182 字,大约阅读时间需要 10 分钟。

1、

2、题目大意:

N 个小孩围成一圈,他们被顺时针编号为 1 到 N。每个小孩手中有一个卡片,上面有一个非 0 的数字,游戏从第 K 个小孩开始,他告诉其他小孩他卡片上的数字并离开这个圈,他卡片上的数字 A 表明了下一个离开的小孩,如果 A 是大于 0 的,则下个离开的是左手边第 A 个,如果是小于 0 的,则是右手边的第 -A 个小孩。游戏将直到所有小孩都离开,在游戏中,第 p 个离开的小孩将得到 F(p) 个糖果,F(p) 是 p 的约数的个数,问谁将得到最多的糖果。输出最幸运的小孩的名字和他可以得到的糖果。

题目:

Who Gets the Most Candies?
Time Limit: 5000MS   Memory Limit: 131072K
Total Submissions: 8763   Accepted: 2666
Case Time Limit: 2000MS

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 2Tom 2Jack 4Mary -1Sam 1

Sample Output

Sam 3

Source

, Sempr

 

3、AC代码:

#include
#include
using namespace std;#define N 500005#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int num[N],sum[N*4];char str[N][15];int f[N],cur_i,next_i,cur_n,ans,ans1,cnt,cur;void pushUp(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void build(int l,int r,int rt){ if(l==r) { sum[rt]=1; return ; } int m=(l+r)>>1; build(lson); build(rson); pushUp(rt);}void update(int p,int l,int r,int rt){ if(l==r) { sum[rt]--; next_i=num[l]; cur_n--; if(ans
>1; if(p<=sum[rt<<1]) update(p,lson); else update(p-sum[rt<<1],rson); pushUp(rt);}int main(){ int n,k; for(int i=1; i<=N; i++) { for(int j=1; i*j<=N; j++) { f[i*j]++; } } while(scanf("%d%d",&n,&k)!=EOF) { build(1,n,1); for(int i=1; i<=n; i++) { scanf("%s%d",str[i],&num[i]); } cur_n=n; cur_i=n; next_i=k; cnt=1; ans=0; ans1=1; for(int i=1; i<=n; i++) { if(next_i>=0) cur_i--; cur=(cur_i+next_i%cur_n+cur_n)%cur_n; update(cur+1,1,n,1); cur_i=cur; cnt++; } printf("%s %d\n",str[ans1],ans); } return 0;}

 

转载地址:http://ywcdi.baihongyu.com/

你可能感兴趣的文章
[关注大学生]读“贫困大学生的自白”
查看>>
[互联网关注]李开复教大学生回答如何学好编程
查看>>
[关注大学生]李开复给中国计算机系大学生的7点建议
查看>>
[关注大学生]大学毕业生择业:是当"鸡头"还是"凤尾"?
查看>>
[茶余饭后]10大毕业生必听得歌曲
查看>>
gdb调试命令的三种调试方式和简单命令介绍
查看>>
C++程序员的几种境界
查看>>
VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
查看>>
VUE-Vue.js之$refs,父组件访问、修改子组件中 的数据
查看>>
Vue-子组件改变父级组件的信息
查看>>
Python自动化之pytest常用插件
查看>>
Python自动化之pytest框架使用详解
查看>>
【正则表达式】以个人的理解帮助大家认识正则表达式
查看>>
性能调优之iostat命令详解
查看>>
性能调优之iftop命令详解
查看>>
非关系型数据库(nosql)介绍
查看>>
移动端自动化测试-Windows-Android-Appium环境搭建
查看>>
Xpath使用方法
查看>>
移动端自动化测试-Mac-IOS-Appium环境搭建
查看>>
Selenium之前世今生
查看>>