随笔分类 -
HDU
HDU 1520 Anniversary party
摘要:http://acm.bjtu.edu.cn/vjudge/problem/viewProblem.action?id=669最最基础的树形dp,父子兄弟结构太爽了,学自hh博客View Code #include <iostream>using namespace std ;struct Tree{ int father ; int child ; int brother ; int happy ; int temp ; int MAX(){ return max(happy,temp) ; } void init(){ ...
阅读全文
HDU 1114 Piggy-Bank
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1114完全背包,求最小值View Code #include <iostream>using namespace std ;int V ;int dp[1000001] ;const int INF=0xfffffff ;void CompletePack(int c,int w){ for(int i=c;i<=V;i++) dp[i]=min(dp[i],dp[i-c]+w) ; return ;}int c[50001],w[50001] ;int main(){ in...
阅读全文
HDU 2844 Coins
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2844求的是能买多少种价钱的物品,多重背包教主很经典的男人八题之一。。。不过据说原题要用单调队列优化,这个二进制优化就过了。。。View Code #include <iostream>using namespace std ;int V ;int dp[100001] ;void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c]+w) ; return ;}void CompletePac...
阅读全文
HDU 1059 Dividing
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1059基础的二进制优化的多重背包View Code #include <iostream>using namespace std ;int V ;int dp[200001] ;void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c]+w) ; return ;}void CompletePack(int c,int w){ for(int i=c;i<=V;i++) ...
阅读全文
HDU 1702 ACboy needs your help again!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1702G++交,基本stl栈和队列操作View Code #include <iostream>#include <stack>#include <queue>using namespace std ;int main(){ int t ; scanf("%d",&t) ; while(t--) { int n,m ; string str ; cin >> n >> str ; if(str=="FIFO&qu
阅读全文
HDU 4314 Save the dwarfs
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4314dp,dp[i][j]表示i个小矮人能逃出去j个时需要之前井中剩下的人的最小a高度之和转移方程dp[i][j]=min(dp[i-1][j]-kk[i-1].a,max(dp[i-1][j-1],h-sumA[i-1]-kk[i-1].b))最神的是解题报告直接把a+b排了个序(a+b最小的先逃脱),这个自己没看出来。。。View Code #include <iostream>#include <algorithm>using namespace std ;const int
阅读全文
HDU 4310 Hero
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4310解题报告正解是状压dp,当时做反正就贪心贪过去了。。。运气真好。。。View Code #include <iostream>#include <algorithm>using namespace std ;typedef struct L{ int dps,hp ; double ab ;}L ;L kk[1001] ;bool cmp(L a,L b){ return a.ab>b.ab ;}int main(){ int n ; while(~scanf("
阅读全文
HDU 1849 Rabbit and Grass
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1849Nim博弈View Code #include <iostream>using namespace std ;int main(){ int n ; while(scanf("%d",&n),n) { int a ; int ans=0 ; while(n--) { scanf("%d",&a) ; ans^=a ; } if(!ans) ...
阅读全文
HDU 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2191裸多重背包View Code #include <iostream>#include <algorithm>using namespace std ;int dp[10001] ;int c[101],w[101],num[101] ;int V ;bool cmp(int a,int b){ return a>b ;}void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c
阅读全文
HDU 1171 Big Event in HDU
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1171多重背包,学自背包九讲。re一次,dp数组开多大算起来太纠结,尽可能开大就不会有事了wa一次,dp数组没有memset。。。View Code #include <iostream>using namespace std ;int dp[1000001] ;int v[51],num[101] ;int V ;void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c]+w) ; ret...
阅读全文
HDU 2577 How to Type
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2577大小写打字,注意shift的使用,注意初始化View Code #include <iostream>using namespace std ;int dp[101][3] ;int main(){ int t ; scanf("%d",&t) ; while(t--) { char s[101] ; scanf("%s",s+1) ; int len=strlen(s+1) ; memset(dp,0,sizeof(dp)...
阅读全文
HDU 1159 Common Subsequence
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1159dp[i][j]代表长度为i的串s1与长度为j的串s2的最长公共子串View Code #include <iostream>using namespace std ;int dp[1001][1001] ;int main(){ char s1[1001],s2[1001] ; while(~scanf("%s%s",s1,s2)) { int len1=strlen(s1) ; int len2=strlen(s2) ; memset(dp...
阅读全文
HDU 1421 搬寝室
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1421因为考虑到差的平方最小,所以先把物品按重量排序(这样可以使相邻的两个数更加接近从而取得更优的结果)。dp[i][j]表示i件物品拿j对时最低的疲劳度i等于2*j时,dp[i][j]=dp[i-2][j-1]+(w[i]-w[i-1])^2其他情况时(即i大于2*j),dp[i][j]=min(dp[i-1][j],dp[i-2][j-1]+(w[i]-w[i-1])^2)View Code #include <iostream>#include <algorithm>using
阅读全文
HDU 1328 IBM Minus One
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1328最近发生了好多事,一言难尽。水一道。View Code #include <stdio.h>int main(){ int t ; scanf("%d",&t) ; for(int cas=1;cas<=t;cas++) { char str[51] ; scanf("%s",str) ; printf("String #%d\n",cas) ; for(int i=0;str[i];i++) if(s...
阅读全文
HDU 3293 sort
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3293水一道排序题。。。希望今晚tc好运~View Code #include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct L{ char location[20],type[20],level[20] ; int ll ;}L ;L kk[501] ;int cmp(const void*a,const void*b){ L*c=(L*)a ; L*d=(L*)b ; if(!strcmp(c
阅读全文
HDU 1878 欧拉回路
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1878一个无向图存在欧拉回路,当且仅当该图所有顶点度数都是偶数且该图是连通图。连通图用并查集判断View Code #include using namespace std ;int hash[1002] ;int...
阅读全文
HDU 2407 Knots
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2407yy题View Code #include <iostream>using namespace std ;int main(){ int n ; while(~scanf("%d",&n)) { double ans=1 ; for(int i=n-1;i>=2;i-=2) ans*=(i-1)*1.0/i ; printf("%.5lf\n",ans) ; } return 0 ;}
阅读全文
HDU 2401 Baskets of Gold Coins
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2401水。。View Code #include <iostream>using namespace std ;int main(){ int n,w,d,s ; while(~scanf("%d%d%d%d",&n,&w,&d,&s)) { if(w*n*(n-1)/2==s) printf("%d\n",n) ; else printf("%d\n",(w*n*(n-1)/2-s)/d) ; } ret
阅读全文
HDU 2714 ISBN
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2714水,按要求找到符合要求的解。。View Code #include <iostream>using namespace std ;int main(){ char str[30] ; int i ; while(~scanf("%s",str)) { int cnt=0 ; int pos ; for(i=0;str[i];i++) if(str[i]=='X') cnt+=10 ; ...
阅读全文
HDU 4027 Can you answer these queries?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4027线段树成段更新的题目,开方次数有限,一个区间都是1就lazy。仿hh风格的线段树,真漂亮啊View Code #include <iostream>#include <cmath>using namespace std ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=100002 ;typedef __int64 LL ;LL sum[maxn<<2] ;int l
阅读全文
|
|