码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round 615 div3 Solution

时间:2020-01-28 21:37:34      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:bsp   codeforce   its   path   air   ane   eve   include   ica   

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

#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;
}

  

Codeforces Round 615 div3 Solution

标签:bsp   codeforce   its   path   air   ane   eve   include   ica   

原文地址:https://www.cnblogs.com/psmao/p/12238620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!