动态规划 杭电4001 大连赛区网络赛水题
2012-01-03 19:50
337 查看
看别人说这是打联赛区网络赛的水题,,水题,,,结果水了几个小时,有木有!!!!!!水不水!!!!!!!由于下午刚做了一道类似的题,所以做这道题的时候就感觉简单了一点。。刚开始wa了几次,主要是排序没排好。个人感觉此类题目最主要的还是排好序,能排好序,这道题就基本上解决了。具体来说这道题,就是按长、宽排序,当长和宽都相等时,则按类型序号排序。因为由题意知,类型序号大的条件更严格,因此,在满足条件的前提下,应该先放类型序号大的。最后在遍历一遍,找最大值即可。需要注意的是数据类型,用_int64即可。
题目:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2375 Accepted Submission(s): 636
Problem Description
Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy, now he grows up. In the dead of night, he often misses
something, including a simple game which brings him much happy when he was child. Here are the game rules: There lies many blocks on the ground, little LLL wants build "Skyscraper" using these blocks. There are three kinds of blocks signed by an integer d.
We describe each block's shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is
thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block's length and width must be more or equal to the block's length and width which lies under the block. When di = 1 the block's
length and width must be more or equal to the block's length which lies under the block and width and the block's area must be more than the block's area which lies under the block. When di = 2 the block length and width must be more than the block's length
and width which lies under the block. Here are some blocks. Can you know what's the highest "Skyscraper" can be build using these blocks?
Input
The input has many test cases.
For each test case the first line is a integer n ( 0< n <= 1000) , the number of blocks.
From the second to the n+1'th lines , each line describing the i‐1'th block's a,b,c,d (1 =< ai,bi,ci <= 10^8 , d = 0 or 1 or 2).
The input end with n = 0.
Output
Output a line contains a integer describing the highest "Skyscraper"'s height using the n blocks.
Sample Input
Sample Output
ac代码:
题目:
To Miss Our Children Time
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2375 Accepted Submission(s): 636
Problem Description
Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy, now he grows up. In the dead of night, he often misses
something, including a simple game which brings him much happy when he was child. Here are the game rules: There lies many blocks on the ground, little LLL wants build "Skyscraper" using these blocks. There are three kinds of blocks signed by an integer d.
We describe each block's shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is
thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block's length and width must be more or equal to the block's length and width which lies under the block. When di = 1 the block's
length and width must be more or equal to the block's length which lies under the block and width and the block's area must be more than the block's area which lies under the block. When di = 2 the block length and width must be more than the block's length
and width which lies under the block. Here are some blocks. Can you know what's the highest "Skyscraper" can be build using these blocks?
Input
The input has many test cases.
For each test case the first line is a integer n ( 0< n <= 1000) , the number of blocks.
From the second to the n+1'th lines , each line describing the i‐1'th block's a,b,c,d (1 =< ai,bi,ci <= 10^8 , d = 0 or 1 or 2).
The input end with n = 0.
Output
Output a line contains a integer describing the highest "Skyscraper"'s height using the n blocks.
Sample Input
3 10 10 12 0 10 10 12 1 10 10 11 2 2 10 10 11 1 10 10 11 1 0
Sample Output
24 11
ac代码:
#include <iostream> #include <cstdio> #include <algorithm> #include <string> using namespace std; struct block{ int num; _int64 length; _int64 width; _int64 height; _int64 area; }aa[1005]; bool cmp(block a,block b){ if(a.length==b.length){ if(a.width==b.width) return a.num>b.num; else return a.width<b.width; } return a.length<b.length; } int main(){ // freopen("4.txt","r",stdin); int n; while(scanf("%d",&n)&&n){ _int64 a,b,dp[1005]; for(int i=0;i<n;++i){ scanf("%I64d%I64d%I64d%d",&a,&b,&aa[i].height,&aa[i].num); aa[i].length=a>b?a:b; aa[i].width=a<b?a:b; aa[i].area=aa[i].length*aa[i].width; } sort(aa,aa+n,cmp); for(int i=0;i<n;++i) dp[i]=aa[i].height; _int64 xmax=0; for(int i=1;i<n;++i){ xmax=0; if(aa[i].num==2){ for(int j=0;j<i;++j){ if(aa[j].length<aa[i].length&&aa[j].width<aa[i].width&&dp[j]>xmax) xmax=dp[j]; } } else if(aa[i].num==1){ for(int j=0;j<i;++j){ if(aa[j].length<=aa[i].length&&aa[j].width<=aa[i].width&&aa[j].area<aa[i].area&&dp[j]>xmax) xmax=dp[j]; } } else{ for(int j=0;j<i;++j){ if(aa[j].length<=aa[i].length&&aa[j].width<=aa[i].width&&dp[j]>xmax) xmax=dp[j]; } } //printf("xmax==%d\n",xmax); dp[i]=aa[i].height+xmax; } xmax=0; for(int i=0;i<n;++i) if(dp[i]>xmax) xmax=dp[i]; printf("%I64d\n",xmax); } return 0; }
相关文章推荐
- 动态规划 杭电4001 大连赛区网络赛水题
- 杭电 4004 大连赛区网络赛。
- 【2016-大连赛区网络赛-F】水题(Football Games,hdu 5873)
- 杭电4001 亚洲区预赛大连赛区
- 杭电4004 亚洲区预赛大连赛区
- 【2016-北京赛区网络赛-A】水题(The Book List,hihocoder 1383)
- 【2016-大连赛区网络赛-G】(Friends and Enemies,hdu 5874)
- 大连赛区网络赛部分题目解题报告
- HDU 5461 Largest Point(2015沈阳赛区网络赛+技巧水题)
- HDU 4001 To Miss Our Children Time(2011年大连网络赛 A 贪心+dp)
- HDU/HDOJ 4004 2011大连赛区网络赛 D题
- 有向图的最小生成树(最小树形图)hdu4009 2011大连赛区网络赛1009
- hdu 5869 Different GCD Subarray Query 2016ACM/ICPC大连赛区网络赛1002
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University(模拟水题)
- HDU 4001 To Miss Our Children Time(2011年大连网络赛 A 贪心+dp)
- ACM HDU 4001 To Miss Our Children Time (2011ACM大连赛区网络赛)
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 A. Banana(连通性水题)
- hdu 5869 Different GCD Subarray Query 2016ACM/ICPC大连赛区网络赛1006
- HDU 4278 Faulty Odometer 第37届ACM/ICPC天津赛区网络赛1001题 (简单水题)
- 【2016-大连赛区网络赛-J】线段树,dfs(Weak Pair,hdu 5877)