USACO 1.4 Packing Rectangles(模拟)
2012-10-24 21:26
218 查看
这个题,不简单啊,虽说是模拟,但是需要注意的情况有很多。开始看错了题,理解正确题意之后,依旧写了很久,错了N次后,终于到了最后一组数据,终于给水过去了,最后一种情况我是分两种情况讨论的,也不知写的对不对。。。
/* ID: cuizhe LANG: C++ TASK: packrec */ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <map> #include <algorithm> using namespace std; int px[5],py[5],k[5]; int o[100001],ans,num,sum,temp; void cl() { if(ans > sum*temp) { ans = sum*temp; memset(o,0,sizeof(o)); o[min(sum,temp)] = 1; } else if(ans == sum*temp) { o[min(sum,temp)] = 1; } } void dfs(int x) { int i,j; int mx[5],my[5]; if(x > 4) { for(i = 0; i < 1<<4; i ++) { for(j = 0; j <= 3; j ++) { if(i&(1<<j)) { mx[j] = px[k[j+1]]; my[j] = py[k[j+1]]; } else { my[j] = px[k[j+1]]; mx[j] = py[k[j+1]]; } } sum = my[0]+my[1]+my[2]+my[3];//方法1 temp = mx[0]; for(j = 1; j <= 3; j ++) { temp = max(mx[j],temp); } cl(); sum = max(my[0]+my[1]+my[2],my[3]);//方法2 temp = mx[0]; for(j = 1; j <= 2; j ++) { temp = max(mx[j],temp); } temp += mx[3]; cl(); sum = max(my[0]+my[1],my[3]);//方法3 sum += my[2]; temp = mx[2]; temp = max(temp,mx[0]+mx[3]); temp = max(temp,mx[1]+mx[3]); cl(); sum = my[0]+max(my[1],my[2])+my[3];//方法4 temp = mx[0]; temp = max(mx[1]+mx[2],temp); temp = max(temp,mx[3]); cl(); sum = my[2]+max(my[0],my[1])+my[3];//方法5 temp = mx[2]; temp = max(mx[0]+mx[1],temp); temp = max(temp,mx[3]); cl(); sum = max(mx[0],mx[1])+max(mx[2],mx[3]);//方法6分2种情况 temp = max(my[0]+my[1],my[2]+my[3]); cl(); if(my[0]+my[1] >= my[2]+my[3]) { sum = my[0]+my[1]; if(my[3] > my[1]) { temp = max(mx[3]+max(mx[0],mx[1]),mx[2]+mx[0]); cl(); } else if(my[2] > my[0]) { temp = max(mx[2]+max(mx[0],mx[1]),mx[3]+mx[1]); cl(); } } } } for(i = 1; i <= 4; i ++) { if(!k[i]) { k[i] = x; dfs(x+1); k[i] = 0; } } } int main() { int i,t; freopen("packrec.in","r",stdin); freopen("packrec.out","w",stdout); for(i = 1; i <= 4; i ++) { scanf("%d%d",&px[i],&py[i]); if(px[i] > py[i]) { t = px[i]; px[i] = py[i]; py[i] = t; } } ans = 10000000; dfs(1); printf("%d\n",ans); for(i = 1; i <= 100000; i ++) { if(o[i]) printf("%d %d\n",i,ans/i); } return 0; } /* 4 5 4 5 4 5 1 16 */
相关文章推荐
- 【模拟递规】Mother's Milk 母亲的牛奶 (Usaco_Training 1.4)
- 【模拟枚举】Arithmetic Progressions等差数列(Usaco_Training 1.4)
- USACO-Section 1.4 Mother Milk[模拟][搜索]
- 【模拟递规】Mother's Milk 母亲的牛奶 (Usaco_Training 1.4)
- 【模拟枚举】Arithmetic Progressions等差数列(Usaco_Training 1.4)
- usaco 1.4 Packing Rectangles(枚举模拟 含结构体排序)and poj 1169
- USACO 1.4 Mother's Milk (枚举 + DFS)
- USACO-Section1.4 Prime Cryptarithm (搜索)
- 【USACO2.4.1】两只塔姆沃斯牛 模拟
- USACO 1.1.2 - Greedy Gift Givers(模拟)
- 【USACO】Transformations(模拟)
- USACO Section 1.4 Mother's Milk(BFS)
- USACO section 2.4 The Tamworth Two(算模拟吧)
- Transformations(模拟)(USACO)
- USACO 1.4 Mother's Milk
- luogu P1215 [USACO1.4]母亲的牛奶 Mother's Milk
- USACO 1.4 packrec
- 【BZOJ】1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机(模拟+bfs)
- luogu P1214 [USACO1.4]等差数列 Arithmetic Progressions
- USACO Section 1.4 Packing Rectangles