poj 2886 Who Gets the Most Candies?(线段树+反素数)
来源:互联网 发布:软件研发过程模型 编辑:程序博客网 时间:2024/05/29 13:20
#include<iostream>#include<cstdio>#include<cstring>#include<math.h>#include<algorithm>using namespace std;const int INF=0x3f3f3f3f;const int maxn=500010;int T,n,k;int a[maxn],loc;char name[maxn][15];int antiPrime[]={1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,332640,498960,554400};int factorNum[]={1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40,48,60,64,72,80,84,90,96,100,108,120,128,144,160,168,180,192,200,216};struct segmentTree{int l;int r;int v;}node[3*maxn];void build(int rt,int l,int r){node[rt].l=l;node[rt].r=r;node[rt].v=r-l+1;if(l==r) return ;int mid=(l+r)>>1;build(rt<<1,l,mid);build(rt<<1|1,mid+1,r);}void Update(int rt,int pos){node[rt].v--;if(node[rt].l==node[rt].r){loc=node[rt].r;return ;}if(pos<=node[rt<<1].v)Update(rt<<1,pos);elseUpdate(rt<<1|1,pos-node[rt<<1].v);}int main(){#ifndef ONLINE_JUDGEfreopen("test.in","r",stdin);freopen("test.out","w",stdout);#endifwhile(~scanf("%d%d",&n,&k)){build(1,1,n);for(int i=1;i<=n;i++){scanf("%s%d",name[i],&a[i]);}int i=0;while(antiPrime[i]<=n)i++;int ansNum=factorNum[i-1];int p=antiPrime[i-1];while(p--){n--;Update(1,k);if(!n) break;if(a[loc]>=0)k=(k+a[loc]-2)%n+1;elsek=((k+a[loc]-1)%n+n)%n+1;}printf("%s %d\n",name[loc],ansNum);}return 0;}
附上打表代码:
memset(f,0,sizeof(f));for(int i=1;i<maxn;i++){for(int j=0;j<maxn;j+=i){f[j]++;}}int max=0;for(int i=1;i<maxn;i++){if(f[i]>max){max=f[i];//cout<<i<<",";cout<<f[i]<<",";}}
0 0
- Who Gets the Most Candies?+POJ+线段树+反素数
- POJ 2886 Who Gets the Most Candies?(线段树单点更新+反素数)
- POJ 2886 Who Gets the Most Candies?(线段树 + 约瑟夫环 + 反素数)
- poj 2886 Who Gets the Most Candies?(线段树单点更新+反素数)真难。。。
- POJ - 2886 Who Gets the Most Candies? (反素数+线段树)
- poj 2886 Who Gets the Most Candies?(线段树+反素数)
- 【POJ 2886】 Who Gets the Most Candies?(反素数求最大因子数+线段树)
- 线段树单点更新+反素数 poj-2886-Who Gets the Most Candies
- POJ 2886 Who Gets the Most Candies? (约瑟夫环+反素数+线段树)
- [poj 2886] Who Gets the Most Candies[线段树][约瑟夫环][反素数]
- POJ 2886 Who Gets the Most Candies?(线段树+反素数)
- POJ-2886 Who Gets the Most Candies? 线段树 + 反素数
- poj 2886 Who Gets the Most Candies?(线段树、反素数)
- poj 2886 Who Gets the Most Candies?(数据结构:线段树+DFS反素数打表)
- poj 2886 Who Gets the Most Candies?(线段树+约瑟夫环+反素数)
- POJ 2886 Who Gets the Most Candies? 线段树 反素数
- poj 2886 Who Gets the Most Candies? 【线段树单点更新 + 反素数】
- POJ 2886 Who Gets the Most Candies? 数据结构+线段树+约瑟夫环+反素数
- 对索引存储与散列存储的一些形而上的思考
- Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
- Android之 Animations动画
- 级联菜单(2个tableView共用一个数据源的方式)
- 用file_get_contents抓取网页乱码的2种解决方式
- poj 2886 Who Gets the Most Candies?(线段树+反素数)
- 广度优先搜索的学习
- 业务中多个人工作间的协作思考
- 103. Binary Tree Zigzag Level Order Traversal
- 258. Add Digits LeetCode
- Hibernate配置文件详解
- Codeforces 618 E . Robot Arm
- 104. Maximum Depth of Binary Tree LeetCode
- 【BZOJ2759】一道动态树的好题