poj 2886 线段树 (用反素数)
2013-08-11 14:15
169 查看
题意:有n 个人,每个人有一个卡,上面有一个非零的数。第一次给一个数k,第k个人跳出,然后看第k的卡上数字是多少,如果大于0 则顺时针数那人人跳出。小于零,逆时针数到的那个人跳出,一次类推,第x次跳出的人会得到f(x),f(x)等于x的因子个数,求最大的f(x)
f(x)满足反素数。 线段树的区间存的是有多少人。
如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数. g(x) 表示x的约数的个数
f(x)满足反素数。 线段树的区间存的是有多少人。
#include<cstdio> #include<cstring> #include<iostream> using namespace std; #define FF freopen("Input.txt","r",stdin) const int N=5e5+2; int RPrime[]= {//反素数 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 fact[]= {//反素数约数个数 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 Node { char name[20]; int val; }A ,res; struct TREE { int l,r; int sum; int mid() { return (l+r)>>1; } }Tree[N*4]; void Build(int rt,int l,int r) { Tree[rt].l=l; Tree[rt].r=r; Tree[rt].sum=r-l+1; if(l==r) return ; int mid=Tree[rt].mid(); Build(rt<<1,l,mid); Build(rt<<1|1,mid+1,r); } int Query(int rt,int x) { Tree[rt].sum--; if(Tree[rt].l==Tree[rt].r) return Tree[rt].l; if(x<=Tree[rt<<1].sum) return Query(rt<<1,x); else return Query(rt<<1|1,x-Tree[rt<<1].sum); } int main() { //FF; int n,k,i; while(~scanf("%d%d",&n,&k)) { for(i=1;i<=n;i++) scanf("%s%d",A[i].name,&A[i].val); int p,Max,id; for(i=0;RPrime[i]<=n;i++); p=RPrime[i-1]; Max=fact[i-1]; Build(1,1,n); for(i=1;i<=p;i++) { id=Query(1,k);//删掉第k个.得到第k的位置id. if(i==p) break; n--; if(A[id].val>0) k=(k-1+A[id].val-1)%n+1; else k=((k-1+A[id].val)%n+n)%n+1; } printf("%s %d\n",A[id].name,Max); } return 0; }
如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数. g(x) 表示x的约数的个数
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=500001; const int prime[13]={0,2,3,5,7,11,13,17,19,23,29,31,37}; int ct[12],visit ; int Rprime[100],fact[100]; void dfs(int x,int num,int sum) { visit[num]=sum; for(int i=1,tmp=1;i<=min(19,ct[x-1]);i++) { tmp*=prime[x]; ct[x]=i; if(num*tmp<N) dfs(x+1, num*tmp, sum*(i+1)); else break; } } int main() { int i, mm = -1; memset(visit,-1,sizeof(visit)); ct[0] = 19; dfs(1,1,1); int tmp=0; for(i=1;i<N;i++) { if(visit[i]!=-1) { if(mm>=visit[i]) visit[i]=-1; else { Rprime[tmp]=i; fact[tmp++]=visit[i]; mm=visit[i]; } } } return 0; }
相关文章推荐
- 线段树 + 反素数 poj2886
- poj 2886 Who Gets the Most Candies?(线段树单点更新+反素数)真难。。。
- poj 2886 Who Gets the Most Candies? 【线段树单点更新 + 反素数】
- poj2886 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?(线段树 + 约瑟夫环 + 反素数)
- ACM练级日志:POJ 2886 约瑟夫环,线段树和反素数
- poj 2886 Who Gets the Most Candies?(线段树、反素数)
- POJ 2886 Who Gets the Most Candies(线段树模拟约瑟夫环)
- poj 2886 线段树+反素数
- poj~2886~线段树
- poj2886线段树(单点修改,区间查询)
- POJ 2886 线段树 反素数
- POJ 2828 && 2886 线段树?二分?
- 线段树:POJ2886 Who Gets the Most Candies?
- POJ 2886 线段树对约瑟夫问题的模拟
- POJ 2886 线段树单点更新
- poj 2886 Who Gets the Most Candies?(线段树单点更新)
- POJ 2886 Who Gets the Most Candies? (线段树 约瑟夫环问题变种)