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\n");
		else if((n-d)%3) pf("NO\n");
		else pf("YES\n");
	}
	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

扫描二维码关注公众号,回复: 8908672 查看本文章
#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\n");
			goto gg;
		}
	}
	pf("YES\n");
	cout << ans << endl;
	gg:;
	}
	return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/psmao/p/12238620.html