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

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

  

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

时间: 2024-07-30 18:17:52

Codeforces Round 615 div3 Solution的相关文章

【赛时总结】◇赛时&#183;V◇ Codeforces Round #486 Div3

◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了--为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Substrings Sort +传送门+   [暴力模拟] 题意 给出n个字符串,你需要将它们排序,使得对于每一个字符串,它前面的字符串都是它的子串(对于字符串i,则字符串 1~i-1 都是它的子串). 解析 由于n最大才100,所以 O(n3) 的算法都不会爆,很容易想到暴力模拟. 如果字符串i是字符串j的子串

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

Codeforces Round #615(Div.3)解题报告 A. Collecting Coins 注意\(n\)可能不够用的情况. #include<bits/stdc++.h> using namespace std; typedef long long ll; int a, b, c, n; void solve() { cin >> a >> b >> c >> n; int mx = max(max(a, b), c); int

Codeforces Round #605(Div3)A~E

Codeforces Round #605(Div3)A~E A. Three Friends 题意: 给三个数\(a,b,c\),对每一个数字可以进行一次操作,加一减一或者不变. 求三个数两两组合的差值绝对值的最小值. 思路: 先排个序. 假设排序后三个数从小到大是\(a,b,c\). 那么他们的两两差就是\((c-b)+(c-a)+(b-a)=2c-2a\). 为了让他们的\(2c-2a\)最小,那就缩小\(c\),增大\(a\). #include<bits/stdc++.h> usin

CodeForces Round #527 (Div3) C. Prefixes and Suffixes

http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some string ss of length nn consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and s

Codeforces Round #615 (Div. 3). D - MEX maximizing

题面:https://codeforces.com/contest/1294/problem/D 题目大意: 每次都会往你的数列里加一个值,你可以任意加减这个值若干次(但是只能加x或者减x) 然后问最小的不属于这个数列的非负整数是什么 你需要进行的操作是,让这个最小的不属于这个数列的非负整数最大 每次加一个值并且询问一遍 解题思路: 易得到,每一次输出的答案在进行完题目的贪心后会呈现上升趋势,且值最大只可能为序列内元素的个数 所以我们可以让每次加入的值在进行完若干次操作后尽量成为靠前的序列中还没

Codeforces Round #615 (Div. 3). B - Collecting Packages

题面:https://codeforces.com/contest/1294/problem/B 题目大意: 机器人从(0,0)开始,他只能往上'U'或者往右'R'走 坐标系中有着很多包裹,分别在一些点上 机器人需要走过去把这些包裹全部收集起来 问能不能做到 如果能,再输出移动方式,相同移动方式输出字典序最小的方案 解题思路: pair或者结构体排序,x与y的优先级任意,因为下一个包裹必定在当前机器人位置右方/上方/右上方 否则直接输出NO,表示不可能存在这种移动方式 在输出移动方式时,注意能先

题解 Codeforces Round #615 (Div. 3) (CF1294)

A:判断一下和是不是3的倍数,由于只加不减,所以还要判断有没有大于和的1/3. 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #define it register int 5 #define ct const int 6 #define il inline 7 using namespace std; 8 int T,a,b,c,n,x; 9 namespace io{ 10 il c

Codeforces Round #615 (Div. 3) A-F简要题解

contest链接:https://codeforces.com/contest/1294 A. 给出a.b.c三个数,从n中分配给a.b.c,问能否使得a = b = c.计算a,b,c三个数的差值之和,n对其取余,判断是否为0即可. AC代码: 1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring>

Codeforces Round #615 (Div. 3) F. Three Paths on a Tree

F. Three Paths on a Tree 原题链接:https://codeforces.com/contest/1294/problem/F 题目大意: 给定一棵树,选出三点,使三点连成的j简单路径最大.简而言之,三个点连成的边的集合大小. 解题思路: 假设任取一点为三点连线的公共点,最长路径就是这个点到其他三个点的三条最长边之和,可知这个点一定在直径上(画图分析假设不在时的最长路径可反证).所以先求出树的直径,在使用$ans =(a b+a c+b c) / 2$遍历可以得到第三个点