UVA 434 Matty's Blocks
来源:互联网 发布:sql 日志回滚 编辑:程序博客网 时间:2024/06/10 03:44
M比较好计算,N弄了半天时间.
首先对于front面的每一个高度front[i],在rightt面里面尽量先找相等的rightt[j],满足没有被其他相同高度front[k] (k != i)的匹配掉,如果找到了就填上front[i],如果没有相等的,找大于front[i]的最右边的rightt[j],然后填掉,如果依旧找不到,那么就留给rightt那边处理.
对于rightt做法相同.
#include <iostream>#include <cstdio>#include <memory.h>#include <algorithm>using namespace std;const int maxn = 9;int K;int sq[maxn][maxn], front[maxn], rightt[maxn];int used[maxn];int main(){int T;scanf("%d", &T);while(T--){scanf("%d", &K);memset(sq, 0, sizeof(sq));memset(used, 0, sizeof(used));for (int i = 0; i < K; ++i){scanf("%d", &front[i]);}for (int i = 0; i < K; ++i){scanf("%d", &rightt[i]);}int ansN = 0, ansM = 0;for (int i = 0; i < K; ++i){int idx = -1, ff = 0;for (int j = 0; j < K; ++j){if(rightt[j] == front[i]){idx = j;ff = 1;if(!used[j]){used[j] = 1;idx = j;break;}}else if(rightt[j] > front[i] && !ff){idx = j;}}if(idx != -1){sq[i][idx] = front[i];}}for (int i = 0; i < K; ++i){int fl = 0;for (int j = 0; j < K; ++j){if(sq[j][i] == rightt[i]){fl = 1; break;}}if(fl == 0){int idx = -1, ff = 0;for (int j = 0; j < K; ++j){if(front[j] == rightt[i]){idx = j;ff = 1;if(!used[j]){used[j] = 1;idx = j;break;}}else if(front[j] > rightt[i] && !ff){idx = j;break;}}if(idx != -1){sq[idx][i] = rightt[i];}}}for (int i = 0; i < K; ++i){for (int j = 0; j < K; ++j){ansN += sq[i][j];ansM += min(front[i], rightt[j]) - sq[i][j];}}printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n", ansN, ansM);}return 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 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
- UVa 101 The Blocks Problem
- 几何中点/线/多边形模板
- C#多线程学习(三) 生产者和消费者
- 详解Windows 8 RP版教程【系统收藏】
- linux 下如何打开core dump文件开关
- 正整数按位取反等于其负数减一;负整数按位取反等于其正数减一
- UVA 434 Matty's Blocks
- Linux操作系统分析-lab2-进程的创建与可执行程序的加载
- Mysql Field * doesn't have a default value
- 一个项目经理的个人体会、经验总结
- 優先隊列C#版
- 在线咨询相关
- 简约而不简单——Android SimpleAdapter
- 排序法总结
- ADO.NET的对象二