题解:SP11573 TEAM2 - A Famous ICPC Team

题目大意

给你四个正方形的边长,让你求组成大正方形的边长的最小值。

解题思路

假设最总答案是 \(x + y\),如果还存在 \(a + b > x + y\) 则一定有两个正方形重叠起来,与答案矛盾,所以答案为:

\[\max\{a + b, a + c, a + d, b + c, b + d, c + d\} \]

代码

#include <bits/stdc++.h>
#define ull unsigned long long
#define int long long
#define ll __int128
#define ldb long double
#define db double
#define bl bool
#define endl '\n'
#define PII pair<int, int>
#define p_q priority_queue
#define n_m unordered_map
#define il inline
#define re register
#define ve vector
#define bs bitset
using namespace std;

//#define O2 1
#ifdef O2
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#endif

namespace OI {
	template <typename T>
	il T read() {
		T x = 0, f = 1;
		int ch = getchar();
		while (!isdigit(ch)) {
			if (ch == '-') f = -1;
			ch = getchar();
		}
		while (isdigit(ch)) {
			x = (x << 3) + (x << 1) + (ch ^ 48);
			ch = getchar();
		}
		return x * f;
	}
	template <typename TE>
	il void write(TE x) {
		if (x < 0) {
			x = -x;
			putchar('-');
		}
		TE sta[35];
		int top = 0;
		do {
			sta[top++] = x % 10, x /= 10;
		} while (x);
		while (top) putchar(sta[--top] + '0');
	}
	il string read_with_string() {
		string s = "";
		char ch = getchar();
		while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')) {
			s += ch;
			ch = getchar();
		}
		return s;
	}
	il void write_with_string(string s) {
		for (int i = 0; i < s.size(); i++) putchar(s[i]);
	}
}
using namespace OI;

//#define fre 1
#define IOS 1
//#define multitest 1

const int N = 2e5 + 10;
const int M = 4e5 + 10;
const int inf = 1e12;

int a, b, c, d;

il void Init() {
	;
}

il void Solve() {
	;
}

signed main() {
	int T;
#ifdef IOS
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
#ifdef fre
	freopen(".in", "r", stdin);
	freopen(".ans", "w", stdout);
#endif
#ifdef multitest
	cin >> T;
#else
	T = 0;
#endif
	while (cin >> a >> b >> c >> d) {
		T++;
		cout << "Case " << T << ": " << max({
			a + b,
			a + c,
			b + d,
			b + c,
			c + d,
			a + d
		}) << endl;
	}
	return 0;
}
/*
  
 */
posted @ 2024-10-25 11:03  zla_2012  阅读(3)  评论(0编辑  收藏  举报