【Codeforces】Codeforces Round 860 (Div. 2) (ABC)(补赛)

A  Showstopper

题目大意:

解题思路:

看能不能换,如果都不能换,则NO

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 5;
ll T, n;
int a[N], b[N];
void solve() {
	int ok = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	int ma = a[n], mb = b[n];
	for (int i = 1; i < n; i++) {
		if (a[i] > ma && (a[i] > mb || b[i] > ma)) ok = 0;
	}
	for (int i = 1; i < n; i++) {
		if (b[i] > mb && (a[i] > mb || b[i] > ma)) ok = 0;
	}
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}
int main() {
	cin >> T;
	while (T--) solve();
	return 0;
}

Three Sevens

题目大意:

解题思路:

每次记录最晚出现的天数,那么就入栈,如果最后栈的大小小于m,则说明无解

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 5e4 + 5;
ll T, m, n;
int x;
unordered_map<int, bool>mp;
vector<int>g[N];
stack<int>ans;
void solve() {
	mp.clear();
	while (!ans.empty()) ans.pop();
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> n;
		g[i].clear();
		for (int j = 1; j <= n; j++) {
			cin >> x;
			g[i].push_back(x);
		}
	}
	int ok;
	for (int i = m; i >= 1; i--) {
		ok = 1;
		for (int j = 0; j < g[i].size(); j++) {
			int w = g[i][j];
			if (mp[w] == 0) {
				mp[w] = 1;
				if (ok) {
					ans.push(w);
					ok = 0;
				}
			}
		}
	}
	if (ans.size() < m) cout << -1 << endl;
	else {
		while (!ans.empty()) {
			cout << ans.top() << ' ';
			ans.pop();
		}
		cout << endl;
	}
}
int main() {
	cin >> T;
	while (T--) solve();
	return 0;
}

Candy Store

题目大意:

解题思路:

找规律

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
ll T, n;
ll a[N], b[N], c[N], d[N];
inline ll gcd(ll a, ll b) {
	if (b) while ((a %= b) && (b %= a));
	return a + b;
}
inline ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}
	ll cnt = 1;
	int l = 1, r = 2;
	ll res1, res2;
	while (r <= n) {
		res1 = a[l] * b[l];
		res2 = b[l];
		int	ok = 1;
		while (ok && r <= n) {
			res1 = gcd(res1, a[r] * b[r]);
			res2 = lcm(res2, b[r]);
			if (res1 % res2 != 0) ok = 0;
			if (!ok) {
				l = r;
				cnt++;
			}
			r++;
		}
	}
	cout << cnt << endl;
}
int main() {
	cin >> T;
	while (T--) solve();
	return 0;
}

题目大意:

解题思路:

参考代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值