随笔分类 -  2012-1000系列

上一页 1 2 3 4 5 6 ··· 13 下一页

 
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(" 阅读全文
posted @ 2012-07-26 18:14 LegendaryAC 阅读(172) 评论(0) 推荐(0)
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) ... 阅读全文
posted @ 2012-07-26 14:29 LegendaryAC 阅读(174) 评论(0) 推荐(0)
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 阅读全文
posted @ 2012-07-26 11:05 LegendaryAC 阅读(241) 评论(0) 推荐(0)
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... 阅读全文
posted @ 2012-07-26 10:44 LegendaryAC 阅读(156) 评论(0) 推荐(0)
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)... 阅读全文
posted @ 2012-07-23 22:03 LegendaryAC 阅读(133) 评论(0) 推荐(0)
POJ 1949 Chores
摘要:http://poj.org/problem?id=1949一句话破题,“Farmer John's list of chores is nicely ordered, and chore K (K > 1) can have only chores 1,.K-1 as prerequisites.”View Code #include <iostream>using namespace std ;int dp[10001] ;int main(){ int n ; while(~scanf("%d",&n)) { int w,k,maxx 阅读全文
posted @ 2012-07-23 22:01 LegendaryAC 阅读(189) 评论(0) 推荐(0)
POJ 3230 Travel
摘要:http://poj.org/problem?id=3230dp[i][j]表示第i天在城市j取得的最大价值这题要注意初始化,最大价值可能是负的。View Code #include <iostream>using namespace std ;int cost[101][101],income[101][101] ;int dp[101][101] ;int main(){ int n,m ; while(scanf("%d%d",&n,&m),n||m) { for(int i=1;i<=n;i++) for(int j=1;j< 阅读全文
posted @ 2012-07-23 17:19 LegendaryAC 阅读(116) 评论(0) 推荐(0)
POJ 1088 滑雪
摘要:http://poj.org/problem?id=1088dp的方法实在卡的不会做。。。搜索搞了View Code #include <iostream>using namespace std ;int map[101][101],dp[101][101] ;int r,c ;int dfs(int x,int y){ int tab[4][2]={1,0,-1,0,0,1,0,-1} ; if(dp[x][y]) return dp[x][y] ; int maxx=0 ; for(int i=0;i<4;i++) { int xx... 阅读全文
posted @ 2012-07-23 15:57 LegendaryAC 阅读(137) 评论(0) 推荐(0)
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... 阅读全文
posted @ 2012-07-23 15:09 LegendaryAC 阅读(121) 评论(0) 推荐(0)
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 阅读全文
posted @ 2012-07-23 09:43 LegendaryAC 阅读(427) 评论(0) 推荐(0)
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... 阅读全文
posted @ 2012-06-24 22:59 LegendaryAC 阅读(230) 评论(0) 推荐(0)
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 阅读全文
posted @ 2012-06-16 21:15 LegendaryAC 阅读(180) 评论(0) 推荐(0)
HDU 1878 欧拉回路
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1878一个无向图存在欧拉回路,当且仅当该图所有顶点度数都是偶数且该图是连通图。连通图用并查集判断View Code #include using namespace std ;int hash[1002] ;int... 阅读全文
posted @ 2012-06-16 10:50 LegendaryAC 阅读(214) 评论(0) 推荐(0)
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 ;} 阅读全文
posted @ 2012-06-16 08:26 LegendaryAC 阅读(164) 评论(0) 推荐(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 阅读全文
posted @ 2012-06-16 08:02 LegendaryAC 阅读(219) 评论(0) 推荐(0)
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 ; ... 阅读全文
posted @ 2012-06-13 21:00 LegendaryAC 阅读(200) 评论(0) 推荐(0)
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 阅读全文
posted @ 2012-06-13 19:44 LegendaryAC 阅读(198) 评论(0) 推荐(0)
HDU 1698 Just a Hook
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1698做的第一道线段树成段更新的题目,lazy标志起到的作用的延迟更新(为了保证O(logN)的效率,不延迟就变成O(N))。这道题反正就询问一次,最后直接输出即可。View Code #include <iostream>using namespace std ; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1const int maxn=100002 ;int sum[maxn<<2] ;int lazy[ 阅读全文
posted @ 2012-06-12 21:14 LegendaryAC 阅读(164) 评论(0) 推荐(0)
HDU 2795 Billboard
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2795下午做的题,线段树单点更新广告牌高h宽w,尽可能在高处挂广告。注意h可能很大,但是我们注意到h比n大就没有意义了,这时我们让h=n(开始因为这个re了)View Code #include <iostream>using namespace std ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=200002 ;int h,w,n ;int MAX[maxn<<2] ;void 阅读全文
posted @ 2012-06-12 21:10 LegendaryAC 阅读(95) 评论(0) 推荐(0)
HDU 3787 A+B
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3787水View Code #include <iostream>using namespace std ;int pow(int a,int b){ int s=1 ; for(int i=0;i<b;i++) s*=a ; return s ;}int main(){ char a[30],b[30] ; int a1,b1 ; while(~scanf("%s%s",a,b)) { int cnt=0 ; a1=b1=0... 阅读全文
posted @ 2012-06-11 21:41 LegendaryAC 阅读(167) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 13 下一页