poj 2777Count Color】的更多相关文章

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…
题目来源: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组目标颜色,剩下的为待匹配的颜…
Count Color Time Limit: 1000MS Memory Limit: 65536K Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a very long board with length L cen…
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=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 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…
贪心....                    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=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…
一.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…
链接: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 , 但…
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,…
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…
题干 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…
这是道标准的数论优化的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(…
# 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];//当前…
题目链接 代码借鉴此博:http://www.cnblogs.com/vongang/archive/2011/08/19/2146070.html 其中关于max{c[fa]/t[fa]}贪心原则,此博有很好的解释:http://www.cnblogs.com/rainydays/p/3271277.html 在此引用其中几段话: 试想,如果没有父节点排在节点之前的限制,那么这个题目非常简单,只需要将结点按照权值从大到小排列即可.加上了这个限制之后,如果权值最大的那个节点一旦满足了条件(父节点…
和上题一样,只考虑旋转等价,只不过颜色和珠子$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>…
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~2054~Color~a~Tree $ $ solution: $ 我们先从题中抽取信息,因为每个点的费用和染色的次数有关,所以我们可以很自然的想到先给权值大的节点染色.但是题目还说每个节点染色前它的父亲节点也必须被染色,这就有了很多的后效性. 暂时没有办法贪心,我们就只能再找找性质.博主首先想到的是从叶子节点考虑,叶子节点里权值最小的一定最后染色.但是经过自我hack,这个结论也是错的.举个栗子:5-1-1-1-8,这条链上如果以左边第一个1为根,先染5会更优. 叶子节点我们拿他没…
POJ 2409 Let it Bead 这题就是polya公式的直接套用,唯一麻烦的是置换群的种类数,由于可以翻转,所以除了要加上pow(c,gcd(s,i))这些平面旋转的置换群,还要加上翻转的.由于翻转的情况奇偶是不同的,所以需要分开讨论:偶数:pow(c,(s-2)/2+2)*(s/2)+pow(c,(s/2))*(s/2);(里面包含了两个对点和两个对边的旋转) 奇数:pow(c,(s-1)/2+1)*s;(一个点和对边的旋转) #include<iostream> #include…
polya题目:uva 11077 Find the Permutationsuva 10294 Arif in DhakaLA 3641 Leonardo's Notebookuva 11077 Find the PermutationsHOJ 2084 The Colored CubesHOJ 2647 Megaminx POJ 1286 Necklace of BeadsPOJ 2409 Let it BeadTOJ 2795 The Queen's New NecklacesHDU 18…
Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42940   Accepted: 13011 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem.…
题目连接 http://poj.org/problem?id=2777 Count Color Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a very long board with length L centime…
题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释,  参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/201402/277917.html #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; + ; ]; struct n…
题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30995   Accepted: 9285 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of pr…
题目链接:  poj 2777 Count Color 题目大意:  给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C  a  b  c 把区间[a,b]涂为c色,P  a  b 查询区间[a,b]有多少种不同颜色 解题思路:  很明显的线段树的区间插入和区间查询,但是如何统计有多少不同的颜色呢? 如果每个结点数组来存储颜色的种类,空间复杂度很高,而且查询很慢 颜色最多只有30种,可以用位运算中的“按位或|” 颜色也用二进制来处理,和存储: 第一种颜色的二进制表示1 第二种颜色…