Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)
链接:
https://codeforces.com/contest/1263/problem/A
题意:
You have three piles of candies: red, green and blue candies:
the first pile contains only red candies and there are r candies in it,
the second pile contains only green candies and there are g candies in it,
the third pile contains only blue candies and there are b candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
思路:
排序得到r >= g >= b
考虑r >= g+b,答案是g+b
否则让r,g,b三个相等
首先让r=g,r减去r-g, b减去r-g(保证可行,r < g+b => b > r-g)
再让r = g = b,r和g同时减去g-(b-(r-g)),三者最后为b+g-r
考虑三个相等,即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[3];
int t;
cin >> t;
while(t--)
{
for (int i = 0;i < 3;++i)
cin >> a[i];
sort(a, a+3);
if (a[2] >= a[1]+a[0])
cout << a[1]+a[0] << endl;
else
{
int ans = 0;
ans += (a[2]-a[1])+(a[2]-a[0]);
int t = a[0]-a[2]+a[1];
ans += (3*t)/2;
cout << ans << endl;
}
}
return 0;
}
Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)的更多相关文章
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem 水题
A. Sweet Problem the first pile contains only red candies and there are r candies in it, the second ...
- Codeforces Round #367 (Div. 2) C. Hard problem
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #603 (Div. 2) E. Editor 线段树
E. Editor The development of a text editor is a hard problem. You need to implement an extra module ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- Codeforces Round #603 (Div. 2)
传送门 感觉脑子还是转得太慢了QAQ,一些问题老是想得很慢... A. Sweet Problem 签到. Code /* * Author: heyuhhh * Created Time: 2019 ...
- Codeforces Round #603 (Div. 2) (题解)
A. Sweet Problem (找规律) 题目链接 大致思路: 有一点瞎猜的,首先排一个序, \(a_1>a_2>a_3\) ,发现如果 \(a_1>=a_2+a_3\) ,那么 ...
- Codeforces Round #603 (Div. 2) A.Sweet Problem
#include <cstdio> #include <algorithm> using namespace std; int main() { int t; scanf(&q ...
随机推荐
- [转帖]如何获得一个Oracle RAC数据库(从Github - oracle/vagrant-boxes) --- 暂时未测试成功 公司网络太差了..
如何获得一个Oracle RAC数据库(从Github - oracle/vagrant-boxes) 2019-11-20 16:40:36 dingdingfish 阅读数 5更多 分类专栏: 如 ...
- 【题解】Luogu P2447 [SDOI2010]外星千足虫
原题传送门 根据题意,题目给的每个操作就相当于异或上选中的那几只虫子的足数(mod 2)等于0/1 这是一个异或方程组,珂以用高斯消元解出每个虫子的足数(mod 2).所需最小次数或判断有多解 但是看 ...
- Kafka MirrorMaker 跨集群同步工具
一.MirrorMaker介绍 MirrorMaker是Kafka附带的一个用于在Kafka集群之间制作镜像数据的工具.该工具从源集群中消费并生产到目标群集.这种镜像的常见用例是在另一个数据中心提供副 ...
- ajax 执行成功以后返回的数据走的是error方法而不是success方法的问题
今天在一个功能的时候发现写的ajax的方法执行后台代码成功后返回前台时执行的是error方法而不是success方法,代码如下 jQuery('#form').ajaxSubmit({ type: & ...
- [Codeforces] Alex and a Rhombus
A. Alex and a Rhombus time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 图像上划凸多边形(convexHull()函数)
import numpy as npimport cv2 as cvimg=np.zeros((400,410),np.uint8)points=np.random.randint(100,400,( ...
- python爬虫---单线程+多任务的异步协程,selenium爬虫模块的使用
python爬虫---单线程+多任务的异步协程,selenium爬虫模块的使用 一丶单线程+多任务的异步协程 特殊函数 # 如果一个函数的定义被async修饰后,则该函数就是一个特殊的函数 async ...
- Spring MVC Web.xml配置
Web.xml spring&spring mvc 在web.xml中定义contextConfigLocation参数,Spring会使用这个参数去加载所有逗号分隔的xml文件,如果没有这个 ...
- requestAnimationFrame ---- 请求动画帧。
window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画.该方法需要传入一个回调函数作为参数,该回调函数会 ...
- CSS 标签显示模式
标签的类型(显示模式) HTML标签一般分为块标签和行内标签两种类型,它们也称块元素和行内元素. 一.块级元素(block-level) 每个块元素通常都会独自占据一整行或多整行,可以对其设置宽度.高 ...