Description
N Children is sitting in a circle to play a game.
The children is numbered from 1 to N in clockwise order. Each of the them have a card with a Non-zero integer on the it in his/her hand. The game starts from the K-th Child, who tells all the others the an integer on his card and jumps out of the circle . The integer on he card tells the next child into the jump out. Let A denote the integer. If A is positive, the next child would be the A-th child to the left. If A is negative, the next child would be the the (−a)-th.
The game lasts until all children has jumped out of the circle. During the game, the p-th child jumping out would get F(P) candies where f(P) Is the number of positive integers that perfectly divide p. Who gets the most candies?
Test instructions is roughly equivalent to the question of Joseph Ring, one at a time, and then out of the X-Man, where x represents the smallest of the few numbers in the largest number.
Do this problem still do not know what is the inverse prime, with the most stupid method (with the 3s+ time) out of the table, directly copied on the. Then it is the construction of the line segment tree, the segment tree is not difficult to build, that is, the number of people who have not gone out within the range. Then update the words to mark a point for going out, and return the position of the point, as the starting point for the next count. The question is the number of an interval that has not gone out.
Anti-prime words are also in the study, recommended Acdreamer article: http://blog.csdn.net/ACdreamers/article/details/25049767
The code is as follows: (Note: Writing is more chaotic, the level is limited.) )
#include <iostream>#include<cstdio>using namespacestd;Const intremmax[ $][2]={ {1,1},{2,2},{4,3},{6,4},{ A,6}, { -,8},{ $,9},{ -,Ten},{ -, A}, { -, -},{ the, -},{ -, -},{ the, -}, {720, -},{840, +},{1260, $},{1680, +}, {2520, -},{5040, -},{7560, -},{10080, the}, {15120, the},{20160, -},{25200, -},{27720, the}, {45360, -},{50400,108},{55440, -},{83160, -}, {110880,144},{166320, the},{221760,168},{277200, the}, {332640,192},{498960, $},{500001, $}};intn,k;Charname[500005][ -];intnumber[500005];intbit[500005*4];intFINDM (intx) { for(intI=0;i< *;++i)if(remmax[i][0]<=x&&remmax[i+1][0]>x)returni;}voidPushup (intPO) {Bit[po]=bit[po*2]+bit[po*2+1];}voidBuild_tree (intLintRintPO) {Bit[po]= (r-l+1); if(r==l)return; intM= (L+R)/2; Build_tree (L,m,po*2); Build_tree (M+1, r,po*2+1);}intQueryintQlintQrintLintRintPO) { if(ql>qr)return 0; if(ql<=l&&qr>=R)returnBit[po]; intM= (L+R)/2; inttemp=0; if(ql<=M) Temp+=query (ql,qr,l,m,po*2); if(qr>M) Temp+=query (ql,qr,m+1, r,po*2+1); returntemp;}intUpdateintUnintLintRintPO) { --Bit[po]; if(l==R)returnL; intM= (L+R)/2; if(bit[po*2]>=un)returnUpdate (un,l,m,po*2); Else returnUpdate (un-bit[po*2],m+1, r,po*2+1);}intMain () {intTEMP,TEMP1; intN,las; intTIMES,FP; while(~SCANF ("%d%d",&n,&K)) { for(intI=1; i<=n;++i) scanf ("%s%d",name[i],&Number[i]); Build_tree (1N1); Temp=Findm (N); Times=remmax[temp][0]; FP=remmax[temp][1]; Las=0; for(intI=1; i<=times;++i) {if(k>0) {K%= (n-i+1); if(k==0) K=n-i+1; } Else{K%= (n-i+1); if(k==0) K=1; ElseK= (n-i+2)+J; } Temp1=query (las+1N1N1); if(temp1>=k) K= (n-i+1)-(temp1-j); ElseK= (K-Temp1); Temp1=update (K,1N1); Las=Temp1; K=Number[las]; } printf ("%s%d\n", NAME[LAS],FP); } return 0;}View Code
Medium POJ 2886 who Gets the most candies? , inverse prime + line tree.