其他分享
首页 > 其他分享> > CF Edu Round 131 简要题解(ABCD)

CF Edu Round 131 简要题解(ABCD)

作者:互联网

A

分类讨论即可 .

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main()
{
	int T, a11, a12, a21, a22; scanf("%d", &T);
	while (T--)
	{
		scanf("%d%d%d%d", &a11, &a12, &a21, &a22);
		if (!a11 && !a12 && !a21 && !a22) puts("0");
		else if (a11 && a12 && a21 && a22) puts("2");
		else puts("1");
	} return 0;
}

t 宝那个判 \(a\) 里所有数之和的是真妙 .

B

显然 \(d=2\) 最优,然后模拟即可 .

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 5e5 + 233;
vector<int> g[N];
inline void addedge(int u, int v){g[u].emplace_back(v);}
int n;
bool vis[N];
int main()
{
	int T; scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		puts("2");
		for (int i=1; i<=n; i++)
		{
			if (vis[i]) continue;
			vis[i] = true;
			for (int j=i; j<=n; j*=2) vis[j] = true, printf("%d ", j);
		}
		puts("");
		for (int i=1; i<=n; i++) vis[i] = false;
	} return 0;
}

C

二分答案,于是考虑把时间都用满可以做多少工作 check 即可 .

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 5e5 + 233;
int n, m, a[N];
inline bool check(int x)
{
	ll ans = 0;
	for (int i=1; i<=n; i++) ans += min(x, a[i]) + (x - min(x, a[i])) / 2;
	return ans >= m;
}
inline void solve()
{
	scanf("%d%d", &n, &m);
	for (int i=1, x; i<=m; i++) scanf("%d", &x), ++a[x];
	int l = 0, r = 2 * m, ans;
	while (l <= r)
	{
		int mid = (l + r) >> 1;
		if (check(mid)){ans = mid; r = mid - 1;}
		else l = mid + 1;
	}
	for (int i=1; i<=n; i++) a[i] = 0;
	printf("%d\n", ans);
}
int main()
{
	int T; scanf("%d", &T);
	while (T--) solve();
	return 0;
}

D

找到每个 \(a_i\) 能取的区间 \([l,r]\),于是问题就变成每个区间取一个数使得两两不重复 .

二分图匹配会 TLE on #4

可以贪心,枚举左端点,右端点扔到 priority_queue 里面取最小的选即可 .

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 5e5 + 233;
vector<pii> g[N];
int n;
int main()
{
	int T; scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		for (int i=1, x; i<=n; i++)
		{
			scanf("%d", &x);
			int L, R;
			if (x == 0){L = i + 1; R = n;}
			else {L = i / (x + 1) + 1; R = i / x;}
			g[L].emplace_back(make_pair(R, i));
		}
		priority_queue<pii, vector<pii>, greater<pii> > q;
		vector<int> ans(n+5);
		for (int i=1; i<=n; i++)
		{
			for (auto _ : g[i]) q.emplace(_);
			auto _ = q.top(); q.pop();
			ans[_.second] = i;
		}
		for (int i=1; i<=n; i++) printf("%d ", ans[i]);
		puts("");
		for (int i=1; i<=n; i++) g[i].clear();
	} return 0;
}

标签:ABCD,typedef,int,题解,scanf,CF,long,&&,ll
来源: https://www.cnblogs.com/CDOI-24374/p/16463447.html