Educational Codeforces Round 77 5/6

A

/* ***********************************************
Author        :BPM136
Created Time  :2019/11/27 21:55:08
File Name     :A.cpp
************************************************ */
 
#include 
#include 
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define USE_CIN_COUT ios::sync_with_stdio(0)
#define filein(x) freopen(#x".in","r",stdin)
#define fileout(x) freopen(#x".out","w",stdout)
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define mkd(x) freopen(#x".in","w",stdout);
 
using namespace std;
 
int random(int l, int r) {
	static std::random_device rd;
	struct timeb timeSeed;
	ftime(&timeSeed);
	size_t seed = timeSeed.time * 1000 + timeSeed.millitm;  // milli time
	static std::mt19937 gen(seed);
	std::uniform_int_distribution<> u(l, r);
	return u(gen);
}
 
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pii;
 
int main() {
	USE_CIN_COUT;
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int x, y;
		cin >> x >> y;
		ll t = y / x;
		ll num = y - x * t;
		ll num2 = x - num;
		ll ans = num * (t + 1) * (t + 1) + num2 * t * t;
		cout << ans << '\n';
	}
    return 0;
}

B

/* ***********************************************
Author        :BPM136
Created Time  :2019/11/27 22:01:25
File Name     :B.cpp
************************************************ */
 
#include 
#include 
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define USE_CIN_COUT ios::sync_with_stdio(0)
#define filein(x) freopen(#x".in","r",stdin)
#define fileout(x) freopen(#x".out","w",stdout)
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define mkd(x) freopen(#x".in","w",stdout);
 
using namespace std;
 
int random(int l, int r) {
	static std::random_device rd;
	struct timeb timeSeed;
	ftime(&timeSeed);
	size_t seed = timeSeed.time * 1000 + timeSeed.millitm;  // milli time
	static std::mt19937 gen(seed);
	std::uniform_int_distribution<> u(l, r);
	return u(gen);
}
 
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pii;
 
int main() {
	USE_CIN_COUT;
	int T;
	cin >> T;
	while (T--) {
		ll x, y;
		cin >> x >> y;
		if (x > y)
			swap(x, y);
		ll l = 0, r = 2e9, ans = -1;
		while (l <= r) {
			ll mid = (l + r) >> 1;
			if (x + y - 2 * mid >= mid) {
				ans = max(ans, mid);
				l = mid + 1;
			} else
				r = mid - 1;
		}
		if (x + y - 2 * ans == ans && x - ans >= 0 && y - ans >= 0)
			puts("YES");
		else
			puts("NO");
	}
    return 0;
}

C

/* ***********************************************
Author        :BPM136
Created Time  :2019/11/27 22:26:48
File Name     :C.cpp
************************************************ */
 
#include 
#include 
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define USE_CIN_COUT ios::sync_with_stdio(0)
#define filein(x) freopen(#x".in","r",stdin)
#define fileout(x) freopen(#x".out","w",stdout)
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define mkd(x) freopen(#x".in","w",stdout);
 
using namespace std;
 
int random(int l, int r) {
	static std::random_device rd;
	struct timeb timeSeed;
	ftime(&timeSeed);
	size_t seed = timeSeed.time * 1000 + timeSeed.millitm;  // milli time
	static std::mt19937 gen(seed);
	std::uniform_int_distribution<> u(l, r);
	return u(gen);
}
 
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pii;
 
int main() {
	USE_CIN_COUT;
	int T;
	cin >> T;
	while (T--) {
		ll r, b, k;
		cin >> r >> b >> k;
		if (r > b)
			swap(r, b);
		ll g = r * b / __gcd(r, b);
		int ans = 0;
		if (b % r == 0) {
			ll t = b / r - 1;
			if (t < k)
				ans = 1;
			else
				ans = 0;
		} else {
			ll num1 = g / r - 1;
			ll num2 = g / b;
			ll t = num1 / num2 + (num1 % num2 != 0);
			if (t < k)
				ans = 1;
			else
				ans = 0;
		}
		if (ans)
			puts("OBEY");
		else
			puts("REBEL");
	}
    return 0;
}

D

对于trap排个序,然后并查集维护答案就行。

/* ***********************************************
Author        :BPM136
Created Time  :2019/11/27 22:48:04
File Name     :D.cpp
************************************************ */
 
#include 
#include 
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define USE_CIN_COUT ios::sync_with_stdio(0)
#define filein(x) freopen(#x".in","r",stdin)
#define fileout(x) freopen(#x".out","w",stdout)
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define mkd(x) freopen(#x".in","w",stdout);
 
using namespace std;
 
int random(int l, int r) {
	static std::random_device rd;
	struct timeb timeSeed;
	ftime(&timeSeed);
	size_t seed = timeSeed.time * 1000 + timeSeed.millitm;  // milli time
	static std::mt19937 gen(seed);
	std::uniform_int_distribution<> u(l, r);
	return u(gen);
}
 
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pii;
 
int const N = 200005;
 
struct Trap {
	int l, r, d;
 
	bool operator<(Trap const& oth) const {
		return d < oth.d;
	}
} trap[N];
 
int f[N], a[N];
int m, n, k, t;
 
int unsfind(int x) {
	if (f[x] == x)
		return x;
	return f[x] = unsfind(f[x]);
}
 
void insert(Trap const& x, int& tim) {
	for (int i = x.l; i <= x.r; ++i) {
		i = unsfind(i);
		if (i > x.r)
			break;
		f[i] = i + 1;
		tim += 2;
	}
}
 
int main() {
	USE_CIN_COUT;
	cin >> m >> n >> k >> t;
	for (int i = 1; i <= m; ++i)
		cin >> a[i];
	for (int i = 1; i <= k; ++i)
		cin >> trap[i].l >> trap[i].r >> trap[i].d;
	for (int i = 1; i <= n + 1; ++i)
		f[i] = i;
	sort(trap + 1, trap + k + 1);
	reverse(trap + 1, trap + k + 1);
	int tim = n + 1, ans = 2e5, p = 1;
	for (; ans >= 0; --ans) {
		while (p <= k && trap[p].d == ans) {
			insert(trap[p], tim);
			++p;
		}
		if (tim > t)
			break;
	}
	int anss = 0;
	for (int i = 1; i <= m; ++i)
		if (a[i] >= ans)
			++anss;
	cout << anss << '\n';
    return 0;
}

E

我竟然没想出来这个,菜死了
显然最大的那个人要打爆 n 2 \frac{n}{2} 2n个人,然后我要贿赂他,然后,要么是 n 2 − 1 \frac{n}{2} - 1 2n1那个人,要么是在这两个人中间的那些人里面,我要贿赂一个人(当然如果你都能打爆里面的所有人就不用贿赂了),然后一直这样做下去,贪心就好了。

/* ***********************************************
Author        :BPM136
Created Time  :2019/11/27 23:13:48
File Name     :E.cpp
************************************************ */
 
#include 
#include 
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define USE_CIN_COUT ios::sync_with_stdio(0)
#define filein(x) freopen(#x".in","r",stdin)
#define fileout(x) freopen(#x".out","w",stdout)
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define mkd(x) freopen(#x".in","w",stdout);
 
using namespace std;
 
int random(int l, int r) {
	static std::random_device rd;
	struct timeb timeSeed;
	ftime(&timeSeed);
	size_t seed = timeSeed.time * 1000 + timeSeed.millitm;  // milli time
	static std::mt19937 gen(seed);
	std::uniform_int_distribution<> u(l, r);
	return u(gen);
}
 
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pii;
 
int const N = 1000005;
 
struct node {
	int s, v;
	bool operator<(node const& oth) const {
		return v > oth.v;
	}
} b[N];
int n;
 
int main() {
	USE_CIN_COUT;
	cin >> n;
	int p = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> b[i].v;
		b[i].s = i;
		if (b[i].v == -1) {
			p = i;
			b[i].v = 0;
		}
	}
	for (int i = 1; i < p; ++i)
		b[i].v = 0;
	ll ans = 0;
	auto q = priority_queue<node>();
	for (int i = n, id = p; i > id; i >>= 1) {
		q.push(b[i]);
		ans += q.top().v;
		q.pop();
		for (int j = i - 1; j > i / 2; --j)
			q.push(b[j]);
	}
	cout << ans << '\n';
    return 0;
}

你可能感兴趣的:(codeforces,ACM补题)