一:素数的基本求法:bool pd(int x){ if(x==1)return false; for(int i=2;i*i1。那么必然存在点(x/k,y/k),会挡住(x,y)。问题就变成了:求1-N中,所有与N互质的数的个数。这不就是欧拉函数....so,ans=(euler(1)...
分类:
其他好文 时间:
2014-07-28 11:30:40
阅读次数:
240
1.欧拉函数的定义: 欧拉函数phi(x)等于不超过x且与x互素的整数的个数。2.欧拉函数的求法:推导过程见随笔《欧拉函数与容斥原理》.3.代码实现欧拉函数: 1 int euler_phi(int n) 2 { 3 int m=(int)sqrt(n+0.5);//取一半就行,简化计算 4...
分类:
其他好文 时间:
2014-07-28 11:19:00
阅读次数:
184
欧拉回路解释对于本题我们只要把每个点的度进行记录,判断是否存在奇数度的点,如果是就可以判断不是欧拉回路,如果不是就在一个点出发,进行dfs搜索,看能否走到起点,因为对于欧拉回路是一个闭合的回路,无论在哪个点出发都应当可以走回起点,所以一次性遍历必将经过每个点,如果出现没有走过的点,则不是欧拉回路。 ...
分类:
其他好文 时间:
2014-07-27 22:33:09
阅读次数:
251
没有想到网络流还能解决这一类问题,完全想不到@_@一开始把所有的无向边制定任意方向有当做有向边看,然后统计每个点的入度和出度。以前有向图的欧拉回路判定是每个点的入读都等于出度,这样可以保证可以回到起点,现在在一些边可以调换方向的情况下,所有定点的入度和出度之差必定为偶数,因为调换任意一条边的方向都会...
分类:
其他好文 时间:
2014-07-27 22:25:29
阅读次数:
270
和西安邀请赛D题类似的题目
这道题会爆栈,所以要非递归写,但是看了很久其实代码没理解,回头重写
#include
#include
#include
using namespace std;
const int SIZE = 100000+10;
int a,s;
int sta[SIZE*10],li[SIZE*10];
char ans[SIZE*10];
void s...
分类:
其他好文 时间:
2014-07-27 11:29:42
阅读次数:
160
奇怪的是,我的判定是不是联通的部分出问题了
先贴个对的:
#include
#include
#include
#include
#include
using namespace std;
const int SIZE = 100000+10;
const int SSIZE = 1000 +10;
const int tb = 26;
int idx(char x)
{...
分类:
其他好文 时间:
2014-07-27 11:29:22
阅读次数:
185
Description
You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line such that the colors of the endpoin...
分类:
其他好文 时间:
2014-07-26 15:24:43
阅读次数:
294
http://poj.org/problem?id=2773
题意:输入n,k,求与n不互素的第k个数,k可能大于n。
思路:以n=6为例,与6互素的数有一定规律。{1,5},{7,12},{13,18}......,发现在[1,n],[n+1,n*2]......[m*n+1,(m+1)*n]区间内素数个数相同,且对应位置的数都相差n的整数倍。因此只要求出[1,n]内的与n互...
分类:
移动开发 时间:
2014-07-26 02:25:36
阅读次数:
222
分析: 基础的欧拉路算法,变化在于要求每条边正向和反向各走一遍。 链式前向星构图,只要标记走过的单向边,边找边输出即可。code#include #include using namespace std;struct node { int v, ne;} edge[100009];int h...
分类:
其他好文 时间:
2014-07-26 00:22:06
阅读次数:
221
http://poj.org/problem?id=3090
法雷级数
法雷级数的递推公式很简单:f[1] = 2; f[i] = f[i-1]+phi[i]。
该题是法雷级数的变形吧,答案是2*f[i]-1。
#include
#include
#include
#include
#include
#include
#include
#include...
分类:
其他好文 时间:
2014-07-24 23:13:54
阅读次数:
294