随笔分类 -
HDU
HDU 1248 寒冰王座
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1248我乱搞的,标准做法01背包View Code #include <stdio.h>int test(int n){ if(n<150)return n; if(n>200&&n<300)return n-200; return n%50;}int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n
阅读全文
HDU 1234 开门人和关门人
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1234和祖宗随机题号PK,由于这题first和end的初值赋反了,导致调试10分钟,最后以惨败收场。。。View Code #include <stdio.h>#include <string.h>#define INF 100000000int main(){ int t,n,i; int hb,mb,sb; int he,me,se; int first,end; char name[2][200],namec[200]; scanf("%d",&t);
阅读全文
HDU 1181 变形课
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1181直接bfs,等号写成赋值了,wa两次。。。View Code #include <stdio.h>#include <string.h>char s[200];char graph[50][50];char vis[50];int q[50];int bfs(){ int front=0,rear=1; int ch,i; q[0]=1; while(front<rear) { ch=q[front++]; if(ch=='m'-'a')re
阅读全文
HDU 2116 Has the sum exceeded
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2116判断两个k位带符号数的和有木有溢出。判断的时候注意不能用两个数的和判断,否则溢出的话会有bug。这里的方法是用最值减其中一个数,再和另一个数比较。View Code #include <stdio.h>int k;__int64 a,b;__int64 pow(int x,int y){ int i; __int64 s=1; for(i=0;i<y;i++) s*=x; return s;}#define MAX pow(2,63) int test(){ ...
阅读全文
HDU 1283 最简单的计算机
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1283模拟View Code #include <stdio.h>int main() { int m1,m2,r1,r2,r3,i; char s[300]; while(~scanf("%d%d",&m1,&m2)) { scanf("%s",s); r1=r2=r3=0; for(i=0;s[i];i++) { switch(s[i]) { ...
阅读全文
HDU 2552 三足鼎立
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2552数学推导View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int t; scanf("%d",&t); while(t--) { scanf("%*lf%*lf"); printf("1\n"); } return 0;}
阅读全文
HDU 1213 How Many Tables
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1213和畅通工程是一个意思、、View Code #include #include #include int idx[2000];int n,m;int find(int x){ //找x所在并查集的根节点...
阅读全文
HDU 1232 畅通工程
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1232第一次做并查集,有点小爽。。。View Code #include #include #include int idx[2000];int n,m;int find(int x){ //找x所在并查集的...
阅读全文
HDU 2131 Probability
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2131求字母在单词中出现的概率,无视大小写View Code #include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ char sp,word[210]; int i,len,cnt; while(~scanf("%c%s%*c",&sp,word)) { len=strlen(word); cnt=0; for(i=0;i<len;i++) ...
阅读全文
HDU 2523 SORT AGAIN
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2523求差的绝对值第k大的数,注意相同的差算一个。分析出差的绝对值在[0,2000]这个范围内,由此可以搞出hash数组View Code #include <stdio.h>#include <string.h>#include <stdlib.h>int abs(int a){ return a>0?a:-a;}int a[3000],hash[5000];int main(){ int t,n,k; int i,j; scanf("%d",&
阅读全文
HDU 1196 Lowest Bit
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1196按要求直接做View Code #include <stdio.h>int pow(int a,int b){ int i,s=1; for(i=0;i<b;i++) s*=a; return s;}int main(){ int n,cnt,y; while(scanf("%d",&n),n) { cnt=0; while(1) { y=n%2; n/=2; ...
阅读全文
HDU 2521 反素数
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2521题目蒙人,这题和反素数没关系求一个区间内因子数最多的最小的数View Code #include <stdio.h>#include <string.h>int main(){ int t,a,b,i,j; int cnt[6000]; int max,si; memset(cnt,0,sizeof(cnt)); cnt[1]=1; for(i=2;i<5001;i++) { for(j=2;j<=i/2;j++) if(i%...
阅读全文
HDU 2190 悼念512汶川大地震遇难同胞——重建希望小学
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2190考虑两种砖,得出递推公式。a[i]=a[i-1]+2*a[i-2]View Code #include <stdio.h>int main(){ int n,i; __int64 a[40]={0,1,3}; for(i=3;i<=30;i++) a[i]=a[i-1]+2*a[i-2]; scanf("%d",&n); while(n--) { scanf("%d",&i); printf("%I64d\n"
阅读全文
HDU 2187 悼念512汶川大地震遇难同胞——老人是真饿了
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2187与2111一样,直接贪心即可View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>struct node{ int p,m;}kk[1100];int cmp(const void*a,const void*b){ struct node*c=(struct node*)a; struct node*d=(struct node*)b; retu
阅读全文
HDU 2111 Saving HDU
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2111直接贪心View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>struct node{ int p,m;}kk[110];int cmp(const void*a,const void*b){ struct node*c=(struct node*)a; struct node*d=(struct node*)b; return d->p-
阅读全文
HDU 1995 汉诺塔V
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1995列表画一下,规律即出View Code #include <stdio.h>#include <string.h>#include <stdlib.h>__int64 pow(int a,int b){ int i; __int64 s=1; for(i=0;i<b;i++) s*=a; return s;}__int64 dp[70][70];int main(){ int t,n,m,i,j; for(i=1;i<61;i++) for...
阅读全文
HDU 1564 Play a game
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1564View Code #include <stdio.h>int main(){ int n; while(scanf("%d",&n),n) { if(n%2==0) printf("8600\n"); else printf("ailyanlu\n"); } return 0;}
阅读全文
HDU 1032 The 3n + 1 problem
摘要: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; ...
阅读全文
HDU 1284 钱币兑换问题
摘要: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
阅读全文
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
阅读全文
|
|