Codeforces Round 884 (Div. 1 + Div. 2)(视频讲解A--D)

@[TOC](Codeforces Round 884 (Div. 1 + Div. 2)(视频讲解A–D))

视频链接:Codeforces Round 884 (Div. 1 + Div. 2)(视频讲解A–D)

A Subtraction Game

1、 板书:

Codeforces Round 884 (Div. 1 + Div. 2)(视频讲解A--D)_第1张图片

2、代码

#include
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int a, b;
	cin >> a >> b;
	cout << a + b << endl;	
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

B Permutations & Primes

1、板书

Codeforces Round 884 (Div. 1 + Div. 2)(视频讲解A--D)_第2张图片

2、代码

#include
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n);
	if(n <= 2)
	{
		for(int i = 1; i <= n; i ++)
		{	
			cout << i << " ";
		}
		cout << endl;
		return;
	}
	a[(n - 1) / 2] = 1;
	a[0] = 2;
	a[n - 1] = 3;

	int tmp = 4;
	for(int i = 0; i < n; i ++)
		if(a[i] == 0)
			a[i] = tmp ++;

	for(int i = 0; i < n; i ++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

C Particles

1、板书

Codeforces Round 884 (Div. 1 + Div. 2)(视频讲解A--D)_第3张图片

2、代码

#include
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int>a, b;
	for(int i = 0; i < n; i ++)
	{
		int x;
		cin >> x;
		if(i % 2)
			a.push_back(x);
		else
			b.push_back(x);
	}

	if(n == 1)
	{
		cout << b[0] << endl;
		return;
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int ans1 = 0, ans2 = 0;
	if(a[a.size() - 1] < 0)
		ans1 = a[a.size() - 1];
	else
	{
		for(int i = a.size() - 1; i >=0; i --)
		{
			if(a[i] > 0)
				ans1 += a[i];
			else
				break;
		}
	}

	if(b[b.size() - 1] < 0)
		ans2 = b[b.size() - 1];
	else
	{
		for(int i = b.size() - 1; i >=0; i --)
		{
			if(b[i] > 0)
				ans2 += b[i];
			else
				break;
		}
	}

	cout << max(ans1, ans2) << endl;

}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

D Row Major

1、板书

Codeforces Round 884 (Div. 1 + Div. 2)(视频讲解A--D)_第4张图片

2、代码

#include
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	int x;
	for(int i = 1; i <= 26; i ++)
	{
		if(n % i)
		{
			x = i;
			break;
		}
	}
	for(int i = 0; i < n; i ++)
	{
		char c = 'a' + (i % x);
		cout << c;
	}
	cout << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

你可能感兴趣的:(codeforces,比赛记录,c++,算法)