UVA - 434 Matty's Blocks

Posted mthoutai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA - 434 Matty's Blocks相关的知识,希望对你有一定的参考价值。

题意:给你正视和側视图,求最多多少个,最少多少个

思路:贪心的思想。求最少的时候:由于能够想象着移动,尽量让两个视图的重叠。所以我们统计每一个视图不同高度的个数。然后计算。至于的话。就是每次拿正视图的高度去匹配側视求最大

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 1000;

int k;
int view[2][MAXN];

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &k);
		memset(view, 0, sizeof(view));
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < k; j++) {
				int x;
				scanf("%d", &x);
				view[i][x]++;
			}
		int Min = 0, Max = 0;
		for (int i = 1; i < MAXN; i++) 
			Min += i * max(view[0][i], view[1][i]);
		for (int i = 1; i < MAXN; i++)
			for (int j = 1; j < MAXN; j++) 
				Max += min(i, j)*view[0][i]*view[1][j];
		printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n", Min, Max-Min);
	}
	return 0;
}



以上是关于UVA - 434 Matty&#39;s Blocks的主要内容,如果未能解决你的问题,请参考以下文章

UVA 11888 - Abnormal 89&#39;s(Manachar)

UVA 10026 Shoemaker&#39;s Problem

[UVA-11039]Children's Game

Uva 10815-Andy&#39;s First Dictionary(串)

UVA 10881 - Piotr's Ants模拟+思维

UVA_11178_Morley's_Theorem_(向量旋转+直线相交)