Codeforces Round #720 (Div. 2)题解

Posted 尘封陌路

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #720 (Div. 2)题解相关的知识,希望对你有一定的参考价值。

题目链接:
https://codeforces.com/contest/1521

A. Nastia and nearly Good Numbers


一开始题意看错了。。。。

思路:
直接构造。

首先三个数都是A的个数
既然两个不能被B整除。
那么就直接构造 ans1=A* B* 2
ans2=A*(B-1)
ans3=A*(B+1)

然后 按顺序输出,最大的在后面!!。 (比赛的时候这里WA了,幸好是test1)
再特判一下 B=1的时候 输出NO

AC代码

#include<bits/stdc++.h>
using namespace std;
const int N=100;
typedef long long ll;
typedef pair<int,int> PII;
map<char,int> mp;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll a,b;
		cin>>a>>b;
		if(b==1)
		{
			cout<<"NO"<<endl;
			continue;
		}
		ll ans1=2*a*b;
		ll ans2=0,ans3=0;
	    ll k=5;
			ans2=(b-1)*a;
			ans3=(b+1)*a;
			cout<<"YES"<<endl;
		cout<<ans2<<" "<<ans3<<" "<<ans1<<endl;
		
	}
	return 0;
}

B. Nastia and a Good Array


思路:
既然要相邻的互质,并且可以改变2个不同下标的元素。而且修改次数不能超过n次。

(贪心)
: 找到最小的,把最小的左边的数全改了,把最小的右边的数也全改了。
改成最小+1(+2,+3,+4…)

例如 样例中 9 6 3 11 15
就可以改成 5 4 3 4 5
那么修改次数永远都是n-1

AC代码

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=1e5+10;
typedef long long ll;
typedef pair<int,int> PII;
map<char,int> mp;
ll a[N];
int main()
{
	IOS
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		int minv=a[1],mini=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]<minv)
			{
				minv=a[i];
				mini=i;
			}
		}
		ll cnt=minv;
	/*	for(int i=mini-1;i>=1;i--)
		{
			a[i]=--cnt;
		}
		cnt=minv;
		for(int i=mini+1;i<=n;i++)
		{
			a[i]=++cnt;
		} */
		cout<<n-1<<endl;
		for(int i=mini-1;i>=1;i--)
		{
			cout<<i<<" "<<mini<<" "<<++cnt<<" "<<minv<<"\\n";
		}
			cnt=minv;
			for(int i=mini+1;i<=n;i++)
		{
			cout<<i<<" "<<mini<<" "<<++cnt<<" "<<minv<<"\\n";
		}
	}
	return 0;
}

C. Nastia and a Hidden Permutation


交互又不会。。。明天补。。

CDE待补。。。

以上是关于Codeforces Round #720 (Div. 2)题解的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #720 (Div. 2)Codeforces-1521ABC

Codeforces Round #720 (Div. 2) ABCDE题解

Codeforces Round #720 (div2) AB

Codeforces Round #720 (Div. 2), B. Nastia and a Good Array

Codeforces Round #720 (Div. 2) A. Nastia and Nearly Good Num

Codeforces Round #720 (Div. 2) A题解