uva 434 - Matty's Blocks(贪心)
2015-04-27 15:29
357 查看
题意:
给出前视图和右视图,计算出最少需要几个正方体以及至多可再增加几个正方体。解析:
最少的情况就是如果能抵消掉的,就尽量让其抵消,高度相同的只需取一个,高度不同的都要取。最多的话直接模拟,先将正视图一行一行的摆放,然后再讲右视图一列一列的摆放,在放置右视图的过程中只能取较小的。
AC代码:
[code]#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<map> using namespace std; const int N = 10; const int MAXH = 1005; int cntf[MAXH], cntr[MAXH]; int f , r , grid ; int n; int main() { int T; scanf("%d",&T); while(T--){ int minv = 0, maxv = 0; memset(cntf, 0, sizeof(cntf)); memset(cntr, 0, sizeof(cntr)); scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &f[i]); cntf[f[i]]++; } for(int i = 0; i < n; i++) { scanf("%d", &r[i]); cntr[r[i]]++; } for(int i = 0; i < MAXH; i++) { minv += max(cntf[i], cntr[i]) * i; } for(int i = 0; i < n; i++) { memcpy(grid[i], f, sizeof(f)); } for(int k = 0, i = n-1; k < n; i--, k++) { for(int j = 0; j < n; j++) { grid[i][j] = min(grid[i][j], r[k]); maxv += grid[i][j]; } } printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n",minv, maxv-minv); } return 0; }
相关文章推荐
- 【UVA】434-Matty's Blocks
- UVA - 434 Matty's Blocks 逻辑
- UVA434 - Matty's Blocks
- UVA - 434 Matty's Blocks
- 【UVA】434-Matty's Blocks
- uva 434 - Matty's Blocks(贪心)
- UVA434 - Matty's Blocks
- UVA 434 - Matty's Blocks(贪心)
- UVa 10905 Children's Game / 贪心
- UVA 434 Matty's Blocks
- UVa 10905 Children's Game ( 贪心 )
- uva 10041 Vito's Family_贪心
- uva - 10905 - Children's Game(贪心,qsort排序)
- UVA - 10041 Vito's Family(贪心)
- uva 10026 Shoemaker's Problem _贪心
- UVa 10905 Children's Game 贪心
- UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序
- Shoemaker's Problem - UVa 10026 贪心
- UVA - 10905 Children's Game(贪心)
- UVA - 434 Matty's Blocks