Educational Codeforces Round 110 (Div. 2) 个人题解 A~D

C题过得确实有点惊险哈,快1:57才过,只剩三四分钟了……

ABCD

A. Fair Playoff

题意

给a,b,c,d四个人的能力值,然后a,b较量,c,d较量,赢的人再进入决赛。问决赛的两人是不是能力值最大的,是就公平,不是就不公平
分析

嘛,怎么写都可以吧
给一份相对复杂的代码

#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define int long long
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;
 
signed main()
{
   
   
	IOS;
	int  t;
	cin >> t;
	while(t--)
	{
   
   
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int p[4] = {
   
   a, b, c, d};
		sort(p, p + 4, greater<int>());
		if(a < b) swap(a, b);
		if(c < d) swap(c, d);
		if(a < c) swap(a, c);
		if(a == p[0] && c == p[1]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

B. Array Reodering

题意

给定一个数组,现在要你重排这个数组,使得有最多的数对,满足:
1≤i<j≤n,gcd(ai,2aj)>1 1≤i<j≤n, gcd(a_i,2a_j)>1 1ijn,gcd(ai,2aj)>1
分析

贪心。由于数据只有2000,凹了一个O(n2)O(n^2)O(n2)的贪心QWQ。先不看条件1≤i<j≤n1≤i<j≤n1ijn,算出每个数和其他所有数最多形成的数对。然后,如果我们加上了条件1≤i<j≤n1≤i<j≤n1ijn,那么每个数肯定会损失一些数对。贪心的构造是让整个数组损失的数对最小。那么可以猜想,结果是按每个数原本的数对个数降序排序。

粗略证明

(昨天随便想的,但感觉不太严格)

由于把“和其他所有数最多形成的数对”最大的数排在了第一个,故这个最大的数肯定不会有任何损失。进一步地思考,把形成数对大的尽量放前面,其后面的数就越多,前面的数就越少,其原本的数对满足1≤i<j≤n1≤i<j≤n1ijn的机会就越多,所以损失的数对就会越少。因为形成数对大的数损失的机会是更大的,所以需要把它们放在前面,减少损失机会。

代码

#include <bits/stdc++.h>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define lson k<<1
#define rson k<<1|1
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mem(a) memset(a, 0, sizeof(a))
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define int long long
const int inf = 0x3f3f3f3f;
const double dinf = 1e100;
typedef long long ll;
//const ll linf = 9223372036854775807LL;
// const ll linf = 1e18;
using namespace std;
const int maxn = 2005;
int n;
struct node{
   
   
	int x, cnt;
	node(){
   
   
		x = cnt = 0;
	}
}a[maxn];
bool cmp(node x, node y){
   
   
	return x.cnt 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值