Codeforces Round 615 div3 Solution

Posted psmao

tags:

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

Problem A. Collecting Coins

Solution

Observe that the easiest solution would be increase every one‘s number of coins to (max(A,B,C))

Then all we have to do is to distribute the coins left evenly to three of them

which is typically just checking if the number of coins left is divisible to 3

#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define mp make_pair
#define fi first
#define se second
#define VI vector<int>
#define pii pair<int,int>
#define fp freopen
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;

int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
	#endif
	int t;
	sf("%d",&t);
	while(t--)
	{
		int a,b,c,n;
		sf("%d%d%d%d",&a,&b,&c,&n);
		int mx = max(a,max(b,c));
		int d = (mx-a)+(mx-b)+(mx-c);
		if(d > n) pf("NO
");
		else if((n-d)%3) pf("NO
");
		else pf("YES
");
	}
	return 0;
}

  

  

Problem B. Collecting Packages

Solution

Observe that the only situation where there is a solution is you can rearrange packages in a way that the x-cor is increasing and y-cor is increasing simultaneously 

Printing the path would be an easy job to do

#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define mp make_pair
#define fi first
#define se second
#define VI vector<int>
#define pii pair<int,int>
#define fp freopen
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;

const int maxn = 1005;

int n;
pii a[maxn];

int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
	#endif
	int t;
	sf("%d",&t);
	while(t--)
	{
	sf("%d",&n);
	fo(i,1,n) sf("%d%d",&a[i].fi,&a[i].se);
	sort(a+1,a+n+1);
	int cx = 0, cy = 0;
	string ans = "";
	fo(i,1,n)
	{
		while(cx < a[i].fi) 
		{
			cx ++;
			ans += "R";
		}
		while(cy < a[i].se)
		{
			cy ++;
			ans += "U";
		}
		if(cx != a[i].fi || cy != a[i].se)
		{
			pf("NO
");
			goto gg;
		}
	}
	pf("YES
");
	cout << ans << endl;
	gg:;
	}
	return 0;
}

  

以上是关于Codeforces Round 615 div3 Solution的主要内容,如果未能解决你的问题,请参考以下文章

[Codeforces #615 div3]1294E Obtain a Permutation

# Codeforces Round #615 (Div. 3)

Codeforces Round #615(Div.3)解题报告

Codeforces Round #615 (Div. 3)

CodeForces Round #498 div3

Codeforces Round 642 (Div3)