新生讲课防翻车留档Codeforces Round 898 (Div. 4)

Codeforces Round 898 (Div. 4)

A题

纯模拟

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	string s; cin >> s;
	string m = "abc";
	int cnt = 0;
	for (int i = 0; i <= 2; i++) {
		if (s[i] != m[i]) {
			cnt++;
		}
	}
	if (cnt == 0 || cnt == 2) {
		cout << "YES\n";
	}
	else
		cout << "No\n";
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

B

给最小的+1

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	ll ans = 1;
	int n; cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	a[0] += 1;
	for (int i = 0; i < n; i++) {
		ans*=a[i]*1ll;
	}
	cout << ans << '\n';
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

C

模拟

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	int a[11][11] = { };
	for (int i = 1; i <= 10; i++) {
		for (int j = 1; j <= 10; j++) {
			if (j == 1 || j == 10||i==1||i==10) {
				a[i][j] = 1;
			}
			else if (i == 2 || i == 9 || j == 2 || j == 9) {
				a[i][j] = 2;
			}
			else if (i == 3 || i == 8 || j == 3 || j == 8) {
				a[i][j] = 3;
			}
			else if (i == 4 || i == 7 || j == 4 || j == 7) {
				a[i][j] = 4;
			}
			else if (i == 5 || i == 6 || j == 5 || j == 6) {
				a[i][j] = 5;
			}
		}
	}

	vector<string>s(11);
	for (int i = 1; i <= 10; i++) {
		cin >> s[i];
		s[i] = '?' + s[i];
	}
	int ans = 0;
	for (int i = 1; i <= 10; i++) {
		for (int j = 1; j <= 10; j++) {
			if (s[i][j] == 'X') {
				ans += a[i][j];
			}
		}
	}
	cout << ans << '\n';
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

D

贪心一点儿

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'B') {
			cnt++;
			for (int j = i; (j < n)&& (j <= i + k - 1); j++) {
				s[j] = 'W';
			}
		}
	}
	cout << cnt << '\n';
	return;
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

E

二分答案

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
ll n, x;
ll a[N];
bool check(ll m) {
	ll t = x;
	for (int i = 0; i < n; i++) {
		if (a[i] < m) {
			t -= m - a[i];
		}
		if (t < 0) {
			return false;
		}
		if (a[i] >= m)
			break;
	}
	if (t < 0) {
		return false;
	}
	else return true;
}

inline void solve(){
    cin >> n >> x;

	ll l = 0, r = 2e9+5;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a, a + n);

	while (l + 1 < r) {
		ll mid = l + r >> 1;
		if (check(mid)) {
			l = mid;
		}
		else {
			r = mid;
		}
	}
	cout << l << '\n';
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

F

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int maxn = 2e5+5;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
int n, m;
int k, x, y;
int h[maxn];
int a[maxn];
ll pre[maxn];
int l[maxn], r[maxn];
ll cal(int x, int y) {
    if (a[x] > k) {
        return 0;
    }

    int l = x, r = y, res = x;
    while (l <= r) {
        m = (l + r) / 2;
        if (pre[m] - pre[x - 1] <= k) {
            res = m;
            l = m + 1;
        }
        else {
            r = m - 1;
        }
    }

    return res - x + 1;
    //  return pre[res] - pre[x-1];
}

void solve() {
    cin>>n>>k;
    pre[0] = 0;
    for (int i = 1; i <= n; ++i) {
        cin>>a[i];
        pre[i] = pre[i - 1] + a[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin>>h[i];
    }
    for (int i = n; i >= 1; --i) {
        if (i == n || (h[i] % h[i + 1])) {
            r[i] = i;
        }
        else {
            r[i] = r[i + 1];
        }
    }

    ll ans = 0;
    for (int i = 1; i <= n; ++i) {

        ans = max(ans, cal(i, r[i]));
    }
    printf("%lld\n", ans);
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();

	return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值