博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2886 线段树+反素数
阅读量:7029 次
发布时间:2019-06-28

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

Who Gets the Most Candies?
Time Limit: 5000MS   Memory Limit: 131072K
Total Submissions: 12744   Accepted: 3968
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 ≤ K ≤ N) 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

/*poj 2886 线段树+反素数反素数:(1)给定一个数,求一个最小的正整数,使得的约数个数为(2)求出中约数个数最多的这个数反素数以前也大概学习过,但是做这个题的时候并没有想到优化方法问题很严重- -给你n个数围成一圈,然后每个人对应一个数字如果x是正数,则下一个人是左边第x个。如果x为负数,则下一个人是右边第-x个大致思路是没啥问题,但是开始是将所有数进行预处理,求出第i个数的f[i],然后同过线段树判断左右两边的剩余人数,然后TLE后来发现别人都是先反素数打表,rprim[0]表示有rprim[1]个因子时的最大值,然后便能1-n中f[]最大值p的位置。然后只需从1模拟到p求出这时对应的人即可hhh-2016-03-23 23:50:13*/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define lson (i<<1)#define rson ((i<<1)|1)using namespace std;typedef long long ll;const int maxn = 500550;int rprim[35][2] ={ 498960,200,332640,192,277200,180,221760,168,166320,160, 110880,144,83160,128,55440,120,50400,108,45360,100, 27720,96,25200,90,20160,84,15120,80,10080,72, 7560,64,5040,60,2520,48,1680,40,1260,36, 840,32,720,30,360,24,240,20,180,18, 120,16,60,12,48,10,36,9,24,8, 12,6,6,4,4,3,2,2,1,1};struct node{ int l,r; int num; int mid() { return ((l+r)>>1); };} tree[maxn<<2];void update_up(int i){ tree[i].num = tree[lson].num + tree[rson].num;}void build(int i,int l,int r){ tree[i].l = l,tree[i].r = r; if(l == r) { tree[i].num = 1; return ; } int mid = tree[i].mid(); build(lson,l,mid); build(rson,mid+1,r); update_up(i);}void update_down(int i){}int cur;void Insert(int i,int k){ if(tree[i].l == tree[i].r) { cur = tree[i].l; tree[i].num = 0; return ; } update_down(i); int mid = tree[i].mid(); if(k <= tree[lson].num) Insert(lson,k); else Insert(rson,k-tree[lson].num); update_up(i);}int query(int i,int l,int r){ if(tree[i].l >= l && tree[i].r <= r) return tree[i].num; update_down(i); int mid = tree[i].mid(); int all = 0; if(l <= mid) all += query(lson,l,r); if(r > mid) all += query(rson,l,r); return all;}char nam[maxn][13];int a[maxn];int main(){ int k,n,t,m,nex; while(scanf("%d%d",&n,&k) != EOF) { t = 0; while(n < rprim[t][0]) t++; int x = rprim[t][0]; for(int i = 1; i <= n; i++) { scanf("%s%d",nam[i],&a[i]); } build(1,1,n); cur = k,m = n; for(int i = 1; i < x; i++) { //cout << cur << endl; Insert(1,cur); //cout << cur <

  

 

转载于:https://www.cnblogs.com/Przz/p/5409597.html

你可能感兴趣的文章
Moss2010 部署命令
查看>>
Git 操作分支
查看>>
Grid search in the tidyverse
查看>>
hdu 三部曲 Contestants Division
查看>>
day22——创建表、增加数据、查询数据
查看>>
css伪元素实现tootip提示框
查看>>
Python基础知识随手记
查看>>
bzoj 1191 [HNOI2006]超级英雄Hero——二分图匹配
查看>>
关于xshell无法连接到centos的问题
查看>>
关于函数指针的总结
查看>>
采用PHP函数uniqid生成一个唯一的ID
查看>>
Centos7安装32位库用来安装32位软件程序
查看>>
【HMOI】小C的填数游戏 DP+线段树维护
查看>>
java中23种设计模式之6-适配器模式(adapter pattern)
查看>>
Easy C 编程 in Linux
查看>>
SQL Server 事务语法
查看>>
poj3761(反序表)
查看>>
x86寄存器总结
查看>>
jquery easyui ajax data属性传值方式
查看>>
封装了些文件相关的操作
查看>>