随笔分类 -
HDU
HDU 2136 Largest prime factor
摘要: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
阅读全文
HDU 1062 Text Reverse
摘要: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...
阅读全文
HDU 4150 Powerful Incantation
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4150查找不重复字串View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>char a[1100000],b[10]; int main() { int t,ans; int len1,len2; int cnt; scanf("%d%*c",&t); while(t--) { scanf("%s%s%*c&qu
阅读全文
HDU 4144 Bacon's Cipher
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4144数字对应1,字母对应0,五位一算。View Code #include <stdio.h>#include <string.h> #include <stdlib.h>int pow(int a,int b) { int i,s=1; for(i=0;i<b;i++) s*=a; return s; }char a[11000]; char tab[30]={'A','B','C','D','
阅读全文
HDU 1166 敌兵布阵
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1166线段树,单点增减,区间求和View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>#define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int maxn=51000; int sum[maxn<<2]; int nCase=1; int pushup(i
阅读全文
HDU 1720 A+B Coming
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=172016进制输入,10进制输出View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>int main() { int a,b; while(~scanf("%x%x",&a,&b)) printf("%d\n",a+b); return 0; }
阅读全文
HDU 1754 I Hate It
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1754线段树,单点更新,区间最值。学习自http://www.notonlysuccess.com/index.php/segment-tree-complete/View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>#define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const
阅读全文
HDU 1215 七夕节
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1215求N因子的和,从1找到sqrt(n),成对的找,后面的用前面的除View Code #include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>int gao(int n){ int s=0,i,cc; cc=sqrt(n); for(i=1;i<=cc;i++) if(n%i==0&&n/i>cc&&n/i!=n) s+=(i
阅读全文
HDU 1282 回文数猜想
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1282两种想法,用字符串处理或是用数字处理,这里数字处理更简单View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int IsHw(int n){ int p,ans=0; p=n; while(n) { ans=ans*10+n%10; n/=10; } if(ans==p)return 1; return 0;}int Nx...
阅读全文
HDU 2601 An easy problem
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=26012932MS......好险注意:(1)n的数据范围(2)j>=i(3)开方拿出来算因为上面三点挂了几次,勉强过关View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int main() { __int64 n; int t,i,p; int cnt; scanf("%d",&t); while(t--) {
阅读全文
HDU 4143 A Simple Problem
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4143两个for枚举肯定超时,移项因式分解后,只要一个for枚举(y-x)就好了,(y+x)用n去除(y-x)。另外两个小点,关注到(y-x)一定小于等于sqrt(n),并且(y-x)与(y+x)不相等View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int main() { int t,n; int i; int f; scanf("%
阅读全文
HDU 2673 shǎ崽 OrOrOrOrz
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2673排序题,汗。。。View Code #include <stdio.h>#include <stdlib.h>int cmp(const void*a,const void*b){ return *(int*)a-*(int*)b;}int a[11000];int main() { int n; int i,f,cnt1,cnt2; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d
阅读全文
HDU 2674 N!Again
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2674n大于等于2009时取余为0,只要算2009前面的就okView Code #include <stdio.h>#include <stdlib.h>int main() { int n; int ans,i; while(~scanf("%d",&n)) { ans=1; if(n>=2009) printf("0\n"); else { for(i=1;i<=n;i++) ...
阅读全文
HDU 2570 迷瘴
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2570这道题WA了十多次,百思不得其解,百度了一组数据12 1 65 7实数运算一定要修正误差View Code #include <stdio.h>#include <stdlib.h>int cmp(const void*a,const void*b){ return *(int*)a-*(int*)b;}int main() { int t,n,cnt; int v,w,p[200]; int i,j,f; double q,rz,ry; scanf("%d"
阅读全文
HDU 2602 Bone Collector
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2602吾近来又开始翻阅背包九讲,确是神作,又有所感,故水01背包一道祭天。View Code #include <stdio.h>#include <string.h>int main(){ int T,N,V; int i,j; int f[1100],c[1100],w[1100]; scanf("%d",&T); while(T--) { scanf("%d%d",&N,&V); memset(f,0,sizeof(
阅读全文
HDU 2086 A1=?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2086找规律,自己推公式。View Code #include <stdio.h>int main(){ int n,i; double a0,a1,n1,a[5000]; while(~scanf("%d",&n)) { scanf("%lf%lf",&a0,&n1); for(i=0;i<n;i++) scanf("%lf",&a[i]); a1=n*a0+n1; for(i=1;i<=n;
阅读全文
HDU 2067 小兔的棋盘
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2067这道题的状态我很久以前就分析过了,是一道递推题,当初感觉思维很乱没写出来。今天好好研究了一下动态规划,发现用动态规划中记忆化搜索的思想能解决此问题。View Code #include <stdio.h>#include <string.h>int n,flag=1; __int64 d[100][100]; __int64 f(int i,int j) { if(d[i][j]>=1)return d[i][j]; if(j==1)return d[i][j]=i; if
阅读全文
|
|