poj 2154 Color < 组合数学+数论>】的更多相关文章

链接:http://poj.org/problem?id=2154 题意:给出两个整数 N 和 P,表示 N 个珠子,N种颜色,要求不同的项链数, 结果 %p ~ 思路: 利用polya定理解~定理内容: 设是n个对象的一个置换群, 用m种颜色染图这n个对象,则不同的染色方案数为: 其中 , 为 的循环节数~     本题只有旋转一种置换方式,那么共有 N 个置换, 每个置换的循环节为 gcd(N,i)~ 那么结果为∑(N^(gcd(N, i))) %P.  N为 1e9, 不能枚举 i , 但…
和上题一样,只考虑旋转等价,只不过颜色和珠子$1e9$ 一样的式子 $\sum\limits_{i=1}^n m^{gcd(i,n)}$ 然后按$gcd$分类,枚举$n$的约数 如果这个也化不出来我莫比乌斯反演白♂学了 最后结果为 $\frac{1}{n}\sum\limits_{d \mid n}n^d \phi (\frac{n}{d})$ 然后$\frac{1}{n}$可以放进去避免除法 然后欧拉函数显然需要现算,上午$T$了,改成筛质数之后算就好了 #include<iostream>…
Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7873   Accepted: 2565 Description Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of th…
题目:http://poj.org/problem?id=2154 置换的第二道题! 需要优化!式子是ans=∑n^gcd(i,n)/n (i∈1~n),可以枚举gcd=g,则有phi( n/g )个数与n的gcd是g. g是n的约数,成对出现,可以O(sqrt(n))枚举.用不断 /p 的log(n)做法求单个的phi.(不用专门看p是不是质数,此处可以保证一定是质数) 注意pw里的x传进去要先%mod!!!因为它是1e9级别的,一开始(x*=x)%=mod的时候会爆. 如果把n开成long…
Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7630   Accepted: 2507 Description Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of th…
http://poj.org/problem?id=2154 大致题意:由n个珠子,n种颜色,组成一个项链.要求不同的项链数目.旋转后一样的属于同一种.结果模p. n个珠子应该有n种旋转置换.每种置换的循环个数为gcd(i,n).假设直接枚举i,显然不行.可是我们能够缩小枚举的数目. 改为枚举每一个循环节的长度L,那么对应的循环节数是n/L.所以我们仅仅需求出每一个L有多少个i满足gcd(i,n)= n/L.就得到了循环节数为n/L的个数. 重点就是求出这种i的个数. 令cnt = gcd(i,…
这是道标准的数论优化的polya题.卡时卡的很紧,需要用int才能过.程序中一定要注意控制不爆int!!!我因为爆intWA了好久=_=…… 题目简洁明了,就是求 sigma n^gcd(i,n):但是由于n很大,所以直接暴力枚举必然会T.于是我们按照这种题的通常思路按gcd的值分类. gcd(i, n) = 1 的个数很明显为 phi(n); gcd(i, n) = 2 -> gcd(i/2, n/2) = 2 所以个数为 phi(n/2); 这样就ok了, 我们就是要求 sigma phi(…
Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of the necklace can be produced. You should know that the necklace might not use up all the N colors, and…
[题目分析] 数据范围有些大. 然后遍求欧拉函数,遍求和就好了,注意取模. [代码] #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define F(i,j,k) for (int i=j;i<=k;++i) #define D(i,j,k) for (int i=j;i>=k;--i) #de…
枚举位移肯定超时,对于一个位移i.我们须要的是它的循环个数,也就是gcd(i,n),gcd(i,n)个数肯定不会非常多,由于等价于n的约数的个数. 所以我们枚举n的约数.对于一个约数k,也就是循环个数为n/k这种个数有phi[k]种,证明网上有非常多. 所以答案就是 phi[k]*(pow(n,n/k)) (k是n的全部约数) 因为约数会非常大所以不能打表,仅仅能单个算. 再因为最后要除以n,假设做除法就不能直接取模,所以我们在算每一次pow(n,n/k)的时候,都少乘一个n,这样就相当于除法了…
根据polya定理,答案应该是 \[ \frac{1}{n}\sum_{i=1}^{n}n^{gcd(i,n)} \] 但是这个显然不能直接求,因为n是1e9级别的,所以推一波式子: \[ \frac{1}{n}\sum_{i=1}^{n}n^{gcd(i,n)} \] \[ =\frac{1}{n}\sum_{d|n}n^d\sum_{i=1}^{n}[gcd(i,n)==d] \] \[ =\frac{1}{n}\sum_{d|n}n^d\sum_{i=1}^{\frac{d}{n}}[gc…
题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ Math.pow((left.green - right.green), 2)+ Math.pow((left.blue - right.blue), 2)) 表示两个不同颜色的之间的距离(以left和right为例,left和right分别为两种不同的颜色),现给出16组目标颜色,剩下的为待匹配的颜…
http://poj.org/problem?id=2154 还是先套上Burnside引理:\[\begin{aligned} ans & =\sum_{i=1}^n n^{(i,n)-1} \\ & = \sum_{d=1}^n [d|n]\sum_{i=1}^n [d|i]\left[\left(\frac id,\frac nd\right)=1\right]n^{d-1} \\ & = \sum_{d=1}^n [d|n]n^{d-1}\sum_{i=1}^{\frac…
Color Description Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of the necklace can be produced. You should know that the necklace might not use up all…
提交地址:http://poj.org/problem?id=1046 Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32987   Accepted: 16037 Description A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this pro…
贪心....                    Color a Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6647   Accepted: 2249 Description Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is single…
Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33007   Accepted: 16050 Description A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just…
题目:http://poj.org/problem?id=1850 题意:按给定的规则给字母编号. 一个很简单的题目,但是却做了好久.................................. #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][]; void init()//用杨辉三角的方法求组合数,C(n,m) { int i,j; ; i<=; i+…
4403: 序列统计 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 328  Solved: 162[Submit][Status][Discuss] Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第一行包含一个整数T,表示数据组数.第2到第T+1行每行包含三个整数N.L和R,N.L和R的意义如题所述. Output 输出包含T…
http://poj.org/problem?id=2777 注意:a可能比b大 #include <cstdio> #include <cstring> #include <algorithm> #define maxn 1000010 using namespace std; int T,L,O,a,b,c; char ch; struct node { int l,r,co; }tree[*maxn]; ]; void build(int l,int r,int…
鸣谢: http://blog.csdn.net/yhrun/article/details/6908470 http://blog.sina.com.cn/s/blog_6a46cc3f0100tvqg.html 题意:链接君已失效 方法:各种数论 解析:老师找了两道数论题.这是第一道,听说比第二道简单多了.然而我并不会,看题解也是好顿理解,这题太值得做了!不做悔一生. 咳,回归正题.这道题就是一个奇妙的数.问你最短须要多少个8组成的数能整除他?所以你有思路么?并没有!有思路你也不会来看我唠叨…
题目大意:字符的字典序依次递增才是合法的字符串,将字符串依次标号如:a-1 b-2 ... z-26 ab-27 bc-52. 为什么题解都是组合数学的...我觉得数位dp很好写啊(逃 f[pos][pre]前pos位,前一位是pre有几个满足条件的字符串,其实等同于这个字符串的序号是多少 好像数位dp的博客真没什么东西好写的... #include<iostream> #include<cstring> #include<cstdlib> #include<cs…
一.Description A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just such a mapping in a standard twenty-four bit RGB color space. The input consists of a target set…
Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30146   Accepted: 14634 Description A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just…
题目链接 首先利用组合数学知识,枚举两人的总胜场数容易得到 这还不是卷积的形式,直接搞的话复杂度大概是O(n^2)的,肯定会TLE.但似乎和卷积有点像?想半天没想出来..多谢Q巨提醒,才知道可以用下面这个公式进行转化 最后,化得的公式为 另外注意,上式右边是一个卷积的形式,但是,所得和的第一项是不需要加上的(不过图中公式没有体现).结合实际意义大概就是,i==0&&j==0时,gcd(i,j)不存在约数d,虽然0可以被任意正整数整除 & 第一项不为0 #include<bit…
题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, know…
题干 Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is singled out, called the "root" of the tree, and there is a unique path from the root to each of the other nodes. Bob intends to colo…
题意: 给长度为N的学列,然后让你通过置换来使其递增.原序列没有相同的数字. 1 ≤ N ≤ 10,000 ai<=100000 思路: 先找到循环,然后根据贪心只有两种比较好的情况,让循环里边最小的数作为循环的起点,或者在循环外边找到最小的数作为置换的起点. 坑点: wa三次的原因是循环外的那个公式写错...因为最后还是要多换一次的... #include<stdio.h> #include<string.h> #include<algorithm> using…
前记: TM终于决定以后干啥了.这几天睡的有点多.困饿交加之间喝了好多水.可能是灌脑了. 切记两件事: 1.安心当单身狗 2.顺心码代码 题意: 给你N种颜色的珠子,串一串长度问N的项链,要求旋转之后重合的算是同一种项链.问一共有多少中可能.结果模p. 1 <= N <= 1000000000, 1 <= P <= 30000 思路: 首先是我们的POLYA定理,给定的公式是这样的sigma(N^gcd(N,i))/N   i从0到N-1. 然后是优化的问题.因为如果我们枚举i累加…
# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int father[1010]; int next[1010];//当前集合的下个元素(包含i) int pre[1010];//当前集合的上个元素(包含i) int num[1010];//num[i]当前集合储存的点的个数(包含i) int vis[1010]; int sum[1010];//当前…