HDU 1397 Goldbach's Conjecture
摘要: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
阅读全文
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
阅读全文
HRBUST 1328 相等的最小公倍数
摘要:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1328判断n因式分解后是否是a^b的形式,是则输出NO,反之YESView Code #include <stdio.h>#include <math.h>#include <stdlib.h>#include <string.h>int jj(int n){ int i,f1=0,f2=0,t; t=n; for(i=2;i<t;i++) { if(!f1) { if(n%..
阅读全文
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...
阅读全文
POJ 1004 Financial Management
摘要:http://poj.org/problem?id=1004求12个数的平均数、、、太无耻了View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int main() { double s,a[13]; int i; while(~scanf("%lf",&a[0])) { s=a[0]; for(i=1;i<12;i++) { scanf("%lf",a+i); s+=a[...
阅读全文
POJ 2027 No Brainer
摘要:http://poj.org/problem?id=2027判断a<b......脸皮这两天又厚了不少、、、这种题也拿来充数、、、忏悔ingView Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int main() { int t; int a,b; scanf("%d",&t); while(t--) { scanf("%d%d",&a,&b); if(a<b
阅读全文
POJ 2017 Speed Limit
摘要:http://poj.org/problem?id=2017按题意计算路程,直接算View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int main() { int n,i; int s[20],t[20]; int ans; while(scanf("%d",&n),n!=-1) { for(i=0;i<n;i++) scanf("%d%d",s+i,t+i); ans=s[0
阅读全文
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("%
阅读全文
BJTU 1621 A Simple Math Problem
摘要:http://acm.bjtu.edu.cn/problem/detail?pid=1621(1)总矩形数:考虑1行n个,由一个、两个、三个......1*1正方形组成的方法数为n、n-1、n-2......1,和为(n+1)*n/2(2)正方形数:n*m的矩形,不妨设n<m,则最大的矩形为n*n,这样的矩形根据乘法原理有1*(m-n+1)个,依次考虑(n-1)*(n-1)......1*1的矩形,方法数同理可得另附HDU 2524 矩形A+B,与此题一个思路,不过只考虑(1)罢了http://acm.hdu.edu.cn/showproblem.php?pid=2524View Cod
阅读全文
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++) ...
阅读全文
BJTU 1623 Problem C. Course Planning
摘要:http://acm.bjtu.edu.cn/problem/detail?pid=1623贪心,关键点是以课程的结束时间为标准排序View Code #include <stdio.h>#include <stdlib.h>struct node{ __int64 x,y;}kk[110000];int cmp(const void*a,const void*b){ struct node*c=(struct node*)a; struct node*d=(struct node*)b; if(d->y==c->y) return d->x-c-&g
阅读全文
|
|