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