03 2016 档案

摘要:http://poj.org/problem?id=2413 #include #include #include using namespace std; //到第485个fib数才有100位 const int LAST=108; char res[500][110]; //存储fib数 char *pos[500]; //存储每个fib数的首地址 char* Addition(char *... 阅读全文
posted @ 2016-03-19 14:21 &ATM 阅读(352) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2773 说实话这道题。。一点都不Happy好吗 似乎还可以用欧拉函数来解这道题,但正好刚学了容斥原理和二分,就用这个解法吧。 题解:要求输出[1,m]中与m互质的第k个数,先打表,找到m的所有质因数,然后用二分实现,最开始区间为[1,2^60],利用容斥原理去找区间[1,mid]内素数的个数t,不断进行二分,直到所查找的区间[l,r]内素数的个... 阅读全文
posted @ 2016-03-18 21:07 &ATM 阅读(311) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2461 题目很简单,但是由于询问数M可以很大,所以容易超时,这道题学到了在结构体里面写函数的方法,这样子效率更高,否则的话,这道题就TLE了。 根据容斥原理,先把每个小长方形的面积加上,然后看有没有与该小长方形相交的,用dfs实现,当相交面积为0时,则不进行dfs,且同样遵循奇加偶减(但代码里因为是以第二个作... 阅读全文
posted @ 2016-03-18 20:54 &ATM 阅读(284) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1695 翻译题目:给五个数a,b,c,d,k,其中恒a=c=1,x∈[a,b],y∈[c,d],求有多少组(x,y)满足GCD(x,y)=k? //(x,y)和(y,x)视作同一个 题解:既然是要x,y的最大公约数为k,那说明x/k和y/k是互质的,只需在[1,b/k]和[1,d/k]范围内找到适合的x,y即可... 阅读全文
posted @ 2016-03-18 20:52 &ATM 阅读(226) 评论(0) 推荐(0)
摘要:《组合数学》里面的容斥原理,写的。。太乱了啊, 下面是关于容斥原理的详细介绍链接:http://www.cppblog.com/vici/archive/2011/09/05/155103.html 自己理解个粗浅的意思,容斥原理其实就是概率论里面的加法公式的n项延伸, 对于集合Ai有以下原理公式, 原理的意思就是: 要计算n个集合并集的大小,先计算所有单个集合的大小,再减去所有两个集合相... 阅读全文
posted @ 2016-03-18 20:42 &ATM 阅读(374) 评论(0) 推荐(0)
摘要:以下三道都是经典二分,道理都差不多,代码就贴在一起了。 POJ 3122 POJ 3258 POJ 3273 POJ 3122: #include #include #include #include using namespace std; #define PI 3.14159265359 //ÓÃ3.1415926»áWA¡£¡£¡£ double pie[10005]; i... 阅读全文
posted @ 2016-03-18 03:04 &ATM 阅读(264) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1905 题意:将一条直线变成一条弧线(该弧线是圆的一部分),求中心位置发生的位移。 由于精度需要控制好,所以选择用圆半径作为二分的目标,l=0,r=INF,LL为弧线长度,根据半径mid以及弦长L,可以求出对应的弧线长度t=2*asin(0.5*L/mid)*mid,再与LL比较,若t #include #include u... 阅读全文
posted @ 2016-03-18 02:59 &ATM 阅读(225) 评论(0) 推荐(0)
摘要:题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想:选定一个要进行比较的目标,在区间[l,r]之间不断二分,直到取到与目标相等的值。 #include #include #include using namespace std; typedef lo... 阅读全文
posted @ 2016-03-18 02:52 &ATM 阅读(285) 评论(0) 推荐(0)
摘要:矩阵快速幂:http://www.cnblogs.com/atmacmer/p/5184736.html 题目链接 #include #include using namespace std; typedef long long ll; #define MOD 10000 ll a[7],b[7],a0[7],b0[7]; void pow_mod(ll n) { a0[1]=a0... 阅读全文
posted @ 2016-03-17 00:39 &ATM 阅读(290) 评论(0) 推荐(0)
摘要:寒假做的题了,先贴那时写的代码。 POJ 1061 #include #include typedef long long LL; using namespace std; void extend_gcd(LL a,LL b,LL &d,LL &x,LL &y) { if(b==0) { d=a; x=1,y=0; } else... 阅读全文
posted @ 2016-03-17 00:34 &ATM 阅读(183) 评论(0) 推荐(0)
摘要:欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include #include #include #include #include using namespace std; int Euler(int n) { int res=n; for(int i=2;i*i1) res-=(res/n); return res; } int ... 阅读全文
posted @ 2016-03-17 00:29 &ATM 阅读(544) 评论(0) 推荐(0)
摘要:/**********/ #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; /***********GCD**********************/ ll gcd(ll a,... 阅读全文
posted @ 2016-03-17 00:15 &ATM 阅读(504) 评论(0) 推荐(0)
摘要:素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: http://blog.csdn.net/maxichu/article/details/45459533 然后是参考了kuangbin的模板: http://www.cnblogs.com/kuang... 阅读全文
posted @ 2016-03-11 00:05 &ATM 阅读(509) 评论(0) 推荐(0)
摘要:找素数本来是很简单的问题,但当数据变大时,用朴素思想来找素数想必是会超时的,所以用素数筛法。 素数筛法 打表伪代码(用prime数组保存区间内的所有素数): void isPrime() vis[]数组清零;//vis[]数组用于标记是否已被检验过 prime[]数组全赋初值false;//prime[]数组从下标0... 阅读全文
posted @ 2016-03-10 23:51 &ATM 阅读(408) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3710 (说实话对于Tarjan算法在搞图论的时候就没搞太懂,以后得找时间深入了解) (以下有关无向图删边游戏的资料来自论文贾志豪《组合游戏略述——浅谈SG游戏的若干拓展及变形》) 首先,对于无向图的删边游戏有如下定理性质: 1.(Fushion Principle定理)我们可对无向图做如下改动:将图中的任意一个偶环缩成一个新点,任意一个... 阅读全文
posted @ 2016-03-07 02:19 &ATM 阅读(319) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2599 #include #include #include #include #include using namespace std; int n,k,pos; vector g[1005]; bool flag[1005]; int dfs(int k) { for(int i=0;i<g[k].size();i++) ... 阅读全文
posted @ 2016-03-07 02:05 &ATM 阅读(185) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2425 #include #include #include #include using namespace std; struct node { int to,next; }e[10000010]; int head[1010],Ecou; int sg[1010]; void add_edge(int u,int v) { ... 阅读全文
posted @ 2016-03-07 02:04 &ATM 阅读(194) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2068 #include #include #include #include using namespace std; int dp[25][(1<<13)+5];//dp[i][j]表示轮到第i个人取时,剩j个石头 int n,s,m[25]; int DFS(int pos,int remain) { if(dp[pos][r... 阅读全文
posted @ 2016-03-07 02:01 &ATM 阅读(251) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1678 #include #include #include #include using namespace std; const int INF=10e8; int n,a,b,p[10005],dp[10005]; int dfs(int x) { if(dp[x]!=-INF) return dp[x]; ... 阅读全文
posted @ 2016-03-07 02:00 &ATM 阅读(275) 评论(0) 推荐(0)
摘要:(Nim积相关资料来自论文曹钦翔《从“k倍动态减法游戏”出发探究一类组合游戏问题》) 关于Nim积计算的两个函数流程: 代码实现如下: int m[2][2]={0,0,0,1}; int Nim_Multi_Power(int x,int y) { if(x=(1=(1 #include using namespace std; in... 阅读全文
posted @ 2016-03-07 01:57 &ATM 阅读(815) 评论(0) 推荐(0)
摘要:题目链接 #include #include #include using namespace std; int sg[2010]; int get_sg(int n) { if(n<0) return 0; if(sg[n]!=-1) return sg[n]; bool vis[2010]; //莫名其妙! //vis[]数组要声明在函数里,如果放... 阅读全文
posted @ 2016-03-05 03:12 &ATM 阅读(132) 评论(0) 推荐(0)
摘要:题目链接 #include #include #include using namespace std; int sg[205][205]; bool vis[300]; int get_sg(int n,int m) { if(sg[n][m]!=-1) return sg[n][m]; for(int i=2;i<=n-i;i++) vis... 阅读全文
posted @ 2016-03-05 03:10 &ATM 阅读(209) 评论(0) 推荐(0)
摘要:题目链接 #include #include using namespace std; int main() { int n; while(scanf("%d",&n)&&n) {//alice先把环破坏,变成链,然后bob只要在链中间取1或2个 //连续的coins,让链变成左右对称的两条,bob就必胜 if(n==1||n==2) ... 阅读全文
posted @ 2016-03-05 03:09 &ATM 阅读(106) 评论(0) 推荐(0)
摘要:题目链接 #include #include using namespace std; typedef long long ll; int main() { ll n; while(~scanf("%I64d",&n)) {//其实算是 贪心了吧 //先手想赢,他会x2,这样子才能尽量避免让后手赢 //后手想赢,他就会x9,只有乘最大的,他胜算才最大 ... 阅读全文
posted @ 2016-03-05 03:07 &ATM 阅读(135) 评论(0) 推荐(0)
摘要:题目链接 #include #include using namespace std; int main() { int n,k[1005]; int sum,cnt; while(scanf("%d",&n)&&n) { sum=0,cnt=0; for(int i=1;i=(sum^k[i])) //sum^k[i]要加括号()... 阅读全文
posted @ 2016-03-05 03:06 &ATM 阅读(138) 评论(0) 推荐(0)
摘要:题目链接 #include #include #include using namespace std; int a[1005]; int main() { int n; while(~scanf("%d",&n)) {//要后者胜,只要s=0,那么n=(m+1)*r,输出最小的m即可 int len=0; bool flag=0; ... 阅读全文
posted @ 2016-03-05 03:05 &ATM 阅读(237) 评论(0) 推荐(0)
摘要:POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜。 定理证明看此博:http://blog.csdn.net/kk303/article/details/6692506 以下是POJ 1704的AC代码: //棋子只能往左走(最左有界线),可以走任意多格(>=1) /... 阅读全文
posted @ 2016-03-05 02:56 &ATM 阅读(307) 评论(0) 推荐(0)
摘要:这道题没说a b最大多少,所以要声明为long long型,不然会WA! 道理很简单,(默认a>=b)a和b只有以下三种关系: 1.a%b==0 :这种关系下,可能是a/b为整数,也可能是a和b都为0,不论哪种,都会是先者胜; 2.a2*b :这种关系下,下一步总能变成(a,a%b)和(a,a%b+b)两种状态,而这两种状态又与第2种状态(a #include using ... 阅读全文
posted @ 2016-03-01 23:44 &ATM 阅读(182) 评论(0) 推荐(0)
摘要:传送门 以下复制自此处:http://www.xuebuyuan.com/2028180.html 博弈论题目可以用寻找必败状态的方法解决。 第一个必败状态是2001.11.04。由此可以推出其他任何时间的状态。对于除2001.11.04外的其他任何时间,present状态是由能移动到的下两个next状态决定的(当然有些时间只有一个next状态),比如1924.12.19的... 阅读全文
posted @ 2016-03-01 23:24 &ATM 阅读(194) 评论(0) 推荐(0)
摘要:传送门 //有n堆,AB轮流从n堆的一堆中移任意个,可以扔掉,也可以移给其他堆中的一堆 //最先移完的胜 //如果n堆中两两堆数目相等,那肯定是B胜 //但只要有非两两相同的,如xyz,A先, //A可以从最多的那堆(z)移y-x个到x堆,yyp,最终移走p的一定是A #include #include #include #include using namespace std; int mai... 阅读全文
posted @ 2016-03-01 23:20 &ATM 阅读(144) 评论(0) 推荐(0)
摘要:传送门 #include #include #include using namespace std; int main() { int n; while(~scanf("%d",&n)) { int a,res=0; int c=0,g=0; for(int i=0;i=2) c++; else i... 阅读全文
posted @ 2016-03-01 23:18 &ATM 阅读(246) 评论(0) 推荐(0)
摘要:传送门 #include #include #include using namespace std; int main() { int t; scanf("%d",&t); while(t--) { int n,a,res=0; int c=0,g=0;//¹Âµ¥¶Ñ¡¢³äÔ£¶Ñ scanf("%d",&n)... 阅读全文
posted @ 2016-03-01 23:16 &ATM 阅读(132) 评论(0) 推荐(0)
摘要:传送门 #include #include #include #include using namespace std; int main() { int n; while(~scanf("%d",&n)) { int a,res=0; for(int i=0;i<n;i++) { scanf("%d... 阅读全文
posted @ 2016-03-01 23:15 &ATM 阅读(141) 评论(0) 推荐(0)
摘要:传送门 #include #include #include #include #include using namespace std; int main() { int a,b; while(~scanf("%d%d",&a,&b)) { int ok=1; if(a>b) swap(a,b); int k=b-a; ... 阅读全文
posted @ 2016-03-01 23:13 &ATM 阅读(127) 评论(0) 推荐(0)
摘要:经过几天的学习和刷题,总算对博弈论的基础懂了一些,学习过程中参考了以下两位的总结: 博弈总结 博弈论题目列表 博弈题目小结 下面列出一些基础博弈的结论定理(证明过程略): (一)巴什博弈(Bash): 一个堆中有n个物体,两人轮流取,每次至少取1个,至多取m个,最后取完者胜。 取胜法则:令n=(m... 阅读全文
posted @ 2016-03-01 23:07 &ATM 阅读(389) 评论(0) 推荐(0)

……