Codeforces Round #797 (Div. 3)总结

前言:

这次出了两道题,总体来说不是很满意,一是因为一开始属实咱就没登上去,一直过了1个多小时才登上,第二点确实是自己水平有所退步,应该不断提升自己的代码能力,结果不进反退,最近都忙着复习了,思维题没管就凉凉了,C题昨晚都没看到(呜呜呜!)

Problem - A - Codeforces

https://codeforces.com/contest/1690/problem/B

https://codeforces.com/contest/1690/problem/C

A题:

需要注意的点就是尽可能的让中间那个数小,所以在分配的时候就要注意这个原则。

分三种情况进行讨论,一是能被三整除的,二是能n - (n / 3) * 2 - 3==0的即最后一个可以分配1,最后一种就是中间分配n/3+1。

代码如下:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
map<string, int>mp1;
map<int, int>mp2;
const int N = 10010;
int t;
ll n, m;
ll a[N];
int main()
{
	cin >> t;
	while (t--) {
		cin >> n;
		if (n % 3 == 0) {
			cout << n / 3 << " " << n / 3 + 1 << " " << n / 3 - 1 << endl;
			continue;
		}
		ll ans = n - (n / 3) * 2 - 3;
		if (ans==0) {
			cout << n / 3 << " " << n / 3 + 2 << " " << 1 << endl;
			continue;
		}
		cout << n / 3 + 1 << " " << n / 3 + 2 << " " << ans<< endl;
	}
 
}

B题:

        需要注意的点是是b数组+ans(差值)等于a[i],如果b[i]==0,加上ans之后大于a[i],还要注意0的特判与共同数值的特判。

代码如下:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
map<string, int>mp1;
map<int, int>mp2;
const int N = 200010;
int t;
ll n, m;
ll a[N];
ll b[N];
int main()
{
	cin >> t;
	while (t--) {
		cin >> n;
		ll cnt1 = 0;
		ll cnt2 = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (a[i] == 0) {
				cnt1++;
			}
		}
		for (int i = 1; i <= n; i++) {
			cin >> b[i];
			if (b[i] == 0) {
				cnt2++;
			}
		}
		if (cnt1 == n&&cnt2==n) {
			cout << "YES" << endl;
			continue;
		}
		if (cnt1 == n && cnt2 != n) {
			cout << "NO" << endl;
			//cout << 1 << endl;
			continue;
		}
		if (cnt1 != n && cnt2 == n) {
			cout << "YES" << endl;
			continue;
		}
		ll cnt3 = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] == b[i]) {
				cnt3++;
			}
		}
		if (cnt3 == n) {
			cout << "YES" << endl;
			continue;
		}
		int cc = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] <b[i]) {
				cc = 1;
				break;
			}
		}
		if (cc == 1) {
			cout << "NO" << endl;
			//cout << 1 << endl;
			continue;
		}
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] != 0 && b[i] != 0) {
				ans = a[i] - b[i];
				break;
			}
		}
		int flag = 0;
		for (int i = 1; i <= n; i++) {
			if (b[i] == 0) {
				if (b[i] + ans >= a[i]) {
					continue;
				}
			}
			if (b[i] + ans == a[i]) {
				continue;
			}
			flag = 1;
		}
		if (flag == 0) {
			cout << "YES" << endl;
			//cout << 1 << endl;
		}
		else {
			cout << "NO" << endl;
			//cout << 1 << endl;
		}
	}

}

C题:

思路:这个题目思路比较简单,就是两种情况的判断即可,直接看代码吧!

代码如下:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
map<string, int>mp1;
map<int, int>mp2;
const int N = 200010;
int t;
ll n, m;
ll a[N];
ll b[N];
int main()
{
	cin >> t;
	while (t--) {
        cin >> n;
        for (int i = 1; i <=n; i++) {
            cin >> a[i];
        }
        for (int i = 1; i <= n; i++) {
            cin >> b[i];
        }
        for (int i = 1; i <=n; i++) {
            if (i == 1) { 
                ll ans = b[i] - a[i];
                cout << ans<< " "; 
                 continue;
            }
            if (b[i-1] >=a[i]) {
                cout << b[i] - b[i-1] << " ";
            }
            else {
                cout << b[i] - a[i] << " ";
            }
        }
        cout << endl;
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钟一淼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值