2012年4月8日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1032可能存在i>j的情况,此情况下i,j要按原顺序输出View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int a,b,n,cnt,max,t,f; while(~scanf("%d%d",&a,&b)) { max=f=1; if(a>b) { t=a; a=b; ... 阅读全文
posted @ 2012-04-08 22:56 LegendaryAC 阅读(151) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1284dp,转移方程自行yyView Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int dp[10][40000]; int main(){ int n; dp[0][0]=1; for(int i=1;i<4;i++) for(int j=0;j<32768;j++) dp[i][j]=dp[i-1][j]+dp[i][j-i]; wh 阅读全文
posted @ 2012-04-08 17:43 LegendaryAC 阅读(137) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1397和2136有共通之处,学习了构造素数表的方法,在这里初次使用。按因子从小到大的顺序筛选,去掉2的倍数,去掉3的倍数......最后剩下的就是素数了。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int prime[40000];int main(){ int n; for(int i=2;i*i<32768;i++) { if(!p 阅读全文
posted @ 2012-04-08 16:01 LegendaryAC 阅读(216) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2136求n的最大素因子在素数表中的位置。如代码循环,因为如果在前面被计算过则肯定不是素数。View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>int rank[1100000]; int main() { int n,cnt=1; for(int i=2;i<1000001;i++) { if(rank[i])continue; for(in 阅读全文
posted @ 2012-04-08 12:05 LegendaryAC 阅读(268) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1062每个单词逆序输出就可以View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>int main() { int t,len; int i,j; char a[1100]; scanf("%d%*c",&t); while(t--) { gets(a); len=strlen(a); for(i=0;i<le... 阅读全文
posted @ 2012-04-08 02:05 LegendaryAC 阅读(210) 评论(0) 推荐(0) 编辑