UVA - 434 Matty's Blocks 逻辑
来源:互联网 发布:淘宝转链接 编辑:程序博客网 时间:2024/06/06 07:30
题目大意:给出两张视图,正视图和右视图,判断要组成这两个视图至少需要多少个积木,在最少个积木的情况下,还需要多少个积木
解题思路:最少的情况就是如果能抵消掉的,就尽量让其抵消,高度相同的只需取一个,高度不同的都要取
最多的情况是每一列都放着高度相同的积木,拿正视图看,正视图的每一个数字都是一列高度相同的积木
因为有右视图的限制且每一行的积木都是相同的,所以大的不能取,只能取小的,所以要减去相对的值
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define maxn 10int f[10], r[maxn], vis[maxn];int main() { int test, n, m; scanf("%d", &test); while(test--) { int Max = 0; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &f[i]); Max += f[i] * n; } for(int i = 0; i < n; i++) { scanf("%d", &r[i]); for(int j = 0; j < n; j++) { if(f[j] > r[i]) Max -= f[j] - r[i]; } } sort(f,f+n); sort(r,r+n); int ans = 0; int cnt_f = 0, cnt_r = 0; while(cnt_f < n && cnt_r < n) { if(f[cnt_f] == r[cnt_r]) { ans += f[cnt_f]; cnt_f++; cnt_r++; } else if(f[cnt_f] > r[cnt_r]) { ans += r[cnt_r]; cnt_r++; } else{ ans += f[cnt_f]; cnt_f++; } } for(; cnt_f < n; cnt_f++) ans += f[cnt_f]; for(; cnt_r < n; cnt_r++) ans += r[cnt_r]; printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n", ans, Max - ans); } return 0;}
0 0
- UVA - 434 Matty's Blocks 逻辑
- UVA 434 Matty's Blocks
- UVA - 434 Matty's Blocks
- 【UVA】434-Matty's Blocks
- UVA 434 - Matty's Blocks(贪心)
- uva 434 - Matty's Blocks(贪心)
- uva 434 - Matty's Blocks(贪心)
- UVa 434 - Matty's Blocks 解题报告(水题)
- UVA434 - Matty's Blocks
- Blocks UVA
- uva 434(逻辑)
- UVA 10559 Blocks
- UVA The Blocks Problem
- UVA - 10559 Blocks(DP)
- UVa 10365 - Blocks
- Baby's Blocks Gym
- uva 101 the blocks problem
- uva 101 the blocks problem
- 利用AFN进行多图片上传
- ubuntu编译最新版本WebKit
- 图片压缩方法
- 微博(pytohn)数据挖掘注意事项和正确的使用参数
- jvm虚拟机androidy移植-编译篇
- UVA - 434 Matty's Blocks 逻辑
- Swift 计算String占用的空间大小CGRect
- [Linux]好用的软件
- 电能质量问题
- listview如果添加的有Headview和Footview,onItemClick数值异常问题
- 添加和删除hadoop集群中的节点
- 那就开始吧
- serialVersionUID的作用 保存对象到本地文件并读取
- Android Bitmap那些事之如何优化内存