Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

2011年12月1日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1232赤裸裸的并查集我的代码 1 #include <stdio.h> 2 const int N=1000; 3 int set[N]; 4 int find(int x) 5 { 6 return set[x]==x ? x : set[x]=find(set[x]); 7 } 8 void merge(int x,int y) 9 {10 set[find(x)]=find(y);11 }12 int main()13 {14 int n,m;15 while (scan... 阅读全文
posted @ 2011-12-01 21:48 Qiuqiqiu 阅读(117) 评论(0) 推荐(0) 编辑

2011年11月30日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1032注意m>n的情况View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int f(int x) 5 { 6 int c=1; 7 while (x!=1) 8 { 9 if (x%2==0) x/=2;10 else x=x*3+1;11 c++;12 }13 return c;14 }15 int main()16 {17 int m,n;18... 阅读全文
posted @ 2011-11-30 19:48 Qiuqiqiu 阅读(104) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1997我的理解若把n个盘子从柱子a通过柱子b移到柱子c,则先把n-1个盘子从柱子a移动柱子b,再把第n个盘子从a移道c,再把n-1个盘子从b移到a。所以当判断序列是否符合把n个盘子从a移到c时,第n个只能出现在柱子a的最底部,或柱子c的最底部,否则这个序列错的。当第n个盘子在a的最底部时,则继续判断剩下的序列是否把n-1个盘子从a移到b。当第n个盘子在c的最底部时,则继续判断剩下的序列是否把n-1个盘子从b移到c。我的代码 1 #include <stdio.h> 2 #include <s 阅读全文
posted @ 2011-11-30 08:19 Qiuqiqiu 阅读(360) 评论(0) 推荐(0) 编辑

2011年11月29日

摘要: 约瑟夫暴力枚举m的值就行了,怕超时的话就打表我的代码 1 #include <stdio.h> 2 const int N=30; 3 int f[14];//={0,2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881}; 4 int k; 5 int ok(int m) 6 { 7 int n=2*k; 8 int flag[N]={0}; 9 int i,t,p=0;10 for (i=0;i<k;i++)11 {12 t=m%(n-i);13 if... 阅读全文
posted @ 2011-11-29 21:14 Qiuqiqiu 阅读(411) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1249f(n)=f(n-1)*(n-1)View Code 1 #include <stdio.h> 2 const int N=10001; 3 int f[N]={0,2}; 4 int main() 5 { 6 int T,i; 7 scanf("%d",&T); 8 for (i=2;i<N;i++) f[i]=f[i-1]+6*(i-1); 9 while (T--)10 {11 int n;12 scanf("%d",&n) 阅读全文
posted @ 2011-11-29 19:08 Qiuqiqiu 阅读(199) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1789贪心先安排分数大的作业,设它的期限为t,若第t天没被安排,则安排在第t天,否则往前找空闲时间,即t-1,t-2,t-3......1,直到找到第i天空闲,则安排在第i天,若前t天都被安排了,没有空闲时间,则这个作业无法完成另外当t>n时,可令t=n,n天足够完成所有作业了我的代码 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 struct work 5 { 6 int s,t 阅读全文
posted @ 2011-11-29 18:36 Qiuqiqiu 阅读(290) 评论(0) 推荐(0) 编辑

2011年11月28日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1568与 HDU 1060Leftmost Digit 差不多求后几位的话,可以构造矩阵相乘,二分求冪求前几位,不需要,直接运用数学公式和对数的性质来求斐波那契数列通项公式an=(1/√5)* [((1+√5)/2)^n-((1-√5)/2)^n]求x^y的前几位高斯函数x=[x]+{x},[x]为x的整数部分,{x}为x的小数部分运用对数性质,t=x^y=a*10^n(科学计数法)lgt=y*lgx=lga+n (n=[lgt],lga={lgt},因为1<=a<10,所以0<=lga&l 阅读全文
posted @ 2011-11-28 20:31 Qiuqiqiu 阅读(258) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1271若n是奇数,只能去掉a的最后一个数字若n是偶数,枚举每一位数字View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 int ans[100]={0},n; 4 int cmp(const void *a,const void *b) 5 { 6 return *(int*)a-*(int*)b; 7 } 8 int f(int x) 9 {10 if (x==0 || x-x/11*11>9) return -1;11 阅读全文
posted @ 2011-11-28 18:13 Qiuqiqiu 阅读(190) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1215类似于筛选法View Code 1 #include <stdio.h> 2 #include <string.h> 3 const int N=500001; 4 int f[N]; 5 int main() 6 { 7 memset(f,0,sizeof(f)); 8 for (int i=1;i<N;i++) 9 for (int j=i+i;j<N;j+=i) f[j]+=i;10 int T,n;11 scanf("%d",&T) 阅读全文
posted @ 2011-11-28 15:51 Qiuqiqiu 阅读(157) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1060求x^y的前几位高斯函数x=[x]+{x},[x]为x的整数部分,{x}为x的小数部分运用对数性质,t=x^y=a*10^n(科学计数法)lgt=y*lgx=lga+n (n=[lgt],lga={lgt},因为1<=a<10,所以0<=lga<1)a=10^{lgt}e=y*lgx, e=e-[e], a=10^eView Code 1 #include <stdio.h> 2 #include <math.h> 3 int main() 4 { 5 i 阅读全文
posted @ 2011-11-28 15:48 Qiuqiqiu 阅读(100) 评论(0) 推荐(0) 编辑