Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2)
1 second
256 megabytes
standard input
standard output
You have three piles of candies: red, green and blue candies:
- the first pile contains only red candies and there are rr candies in it,
- the second pile contains only green candies and there are gg candies in it,
- the third pile contains only blue candies and there are bb 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.
The first line contains integer tt (1≤t≤10001≤t≤1000) — the number of test cases in the input. Then tt test cases follow.
Each test case is given as a separate line of the input. It contains three integers rr, gg and bb (1≤r,g,b≤1081≤r,g,b≤108) — the number of red, green and blue candies, respectively.
Print tt integers: the ii-th printed integer is the answer on the ii-th test case in the input.
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
1
2
2
10
5
9
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
题意很好理解,一行分别给出三种颜色的糖果数量。每天只能吃两个糖果,而且这两个糖果颜色不能一样。问最多能吃多少天(糖果不一定完全吃完,但是每一天都要严格按照规则)
对a,b,c先从小到大排序。
如果a+b<c,很明显,输出a+b就好了
对于a+b>=c。(a+b+c)/2这个点一定落在b上,那么我们让这个点的左右部分配对就可以了,一共就是(a+b+c)/2了,多出来也没关系。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int a[]; int sum = ;
for(int i = ; i< ;i++)
{
cin>>a[i];
sum+=a[i];
}
sort(a,a+);
if(a[]+a[]<a[])
cout<<a[]+a[]<<endl;
else
cout<<sum/<<endl;
}
}
On the well-known testing system MathForces, a draw of nn rating units is arranged. The rating will be distributed according to the following algorithm: if kk participants take part in this event, then the nn rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants.
For example, if n=5n=5 and k=3k=3, then each participant will recieve an 11 rating unit, and also 22 rating units will remain unused. If n=5n=5, and k=6k=6, then none of the participants will increase their rating.
Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help.
For example, if n=5n=5, then the answer is equal to the sequence 0,1,2,50,1,2,5. Each of the sequence values (and only them) can be obtained as ⌊n/k⌋⌊n/k⌋ for some positive integer kk (where ⌊x⌋⌊x⌋ is the value of xx rounded down): 0=⌊5/7⌋0=⌊5/7⌋, 1=⌊5/5⌋1=⌊5/5⌋, 2=⌊5/2⌋2=⌊5/2⌋, 5=⌊5/1⌋5=⌊5/1⌋.
Write a program that, for a given nn, finds a sequence of all possible rating increments.
The first line contains integer number tt (1≤t≤101≤t≤10) — the number of test cases in the input. Then tt test cases follow.
Each line contains an integer nn (1≤n≤1091≤n≤109) — the total number of the rating units being drawn.
Output the answers for each of tt test cases. Each answer should be contained in two lines.
In the first line print a single integer mm — the number of different rating increment values that Vasya can get.
In the following line print mm integers in ascending order — the values of possible rating increments.
4
5
11
1
3
4
0 1 2 5
6
0 1 2 3 5 11
2
0 1
3
0 1 3
题意呢,就是给n,把其分成k份。每份就是n/k。比如样例一:
n=5: 1 2 3 4 5 6
5 2 1 1 1 0
所以输出: 0 1 2 5
我们看看n的范围,1e9,暴力的话会超时的(菜鸡的我第一发T了)我们观察一下,比如说对于样例一,3,4,5出的结果都是1,但是我们只能输出一个1,有没有办法让遍历
从n=3直接到6,跳过重复项呢?
对于样例一,5/3==1,而5/1==5,即i=5时,n恰好整除,那么我们让i==3直接跳到i==6就好了
3是第一个出现n/i==1的地方,直接让i==3跳到i==6,跳到整除的下一个i,可以跳过重复答案,因为如果n%i==0,那么n/(i+1)必定结果和n/(i)是不一样的
具体的就看代码吧,正好复习一下vector迭代器的敲法.....
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int>vv;
vv.push_back();
for(int i=,j;i<=n;i=j+)
{
vv.push_back(n/i);
j=n/(n/i);
}
sort(vv.begin(),vv.end());
cout<<vv.size()<<endl;
vector<int>::iterator i; //vector迭代器
for(i=vv.begin();i<vv.end();i++)
{
cout<<*i<<" ";
}
cout<<endl;
}
}
Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题的更多相关文章
- 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 #603 (Div. 2) A. Sweet Problem(数学)
链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green an ...
- Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题
C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...
- Codeforces Round #603 (Div. 2) B. PIN Codes 水题
B. PIN Codes A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN code ...
- 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 #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- 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 ...
随机推荐
- 今日份学习:初步的springboot
今日记录 今日份BUG清单 flyway的sql文件有两个下划线 __ , _ 是不可以的. 高版本的freemarker默认的扩展名变成了flth,而不是ftl 今日份用到的网址 1. freema ...
- ElasticSearch学习,入门篇(一)
概念解析 1.什么是搜索 搜索就是在任何场景下,找寻你想要的信息,这个时候你会输入一段要搜索的关键字,然后期望找到这个关键字相关的有效信息. 2.如果用数据库做搜素会怎么样 select * from ...
- 在 Rolling Update 中使用 Health Check【转】
上一节讨论了 Health Check 在 Scale Up 中的应用,Health Check 另一个重要的应用场景是 Rolling Update.试想一下下面的情况: 现有一个正常运行的多副本应 ...
- Day4 - G - 确定比赛名次 HDU - 1285
有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...
- [题解] LuoguP2764 最小路径覆盖问题
传送门 好久没做网络流方面的题发现自己啥都不会了qwq 题意:给一张有向图,让你用最少的简单路径覆盖所有的点. 考虑这样一个东西,刚开始,我们有\(n\)条路径,每条路径就是单一的一个点,那么我们的目 ...
- .NET via C#笔记12——泛型
12 泛型 使用值类型作为参数的泛型容器,传入值类型的参数时,不需要进行装箱 12.1 FCL中的泛型 System.Array中提供了很多泛型方法 AsReadOnly BinarySearch C ...
- VMware Workstation上新建虚拟机
准备开始,话不多少,直接上图 点击创建新的虚拟机或者在文件上面选择新建虚拟机 点击完成就可以了 后面的步骤,是在公司电脑上完成的,新建了一个CentOs1,步骤同上,后面继续,然后需要更改配置,点击虚 ...
- js generator的两个实际应用
generator作为一个用来操作异步的状态机, 遇到yield停止, 通过调用next()来继续操作. 今天就用generator来举例两个实际开发中的应用. 1,抽奖 function draw ...
- Python+Selenium中级篇之8-Python自定义封装一个简单的Log类《转载》
Python+Selenium中级篇之8-Python自定义封装一个简单的Log类: https://blog.csdn.net/u011541946/article/details/70198676
- laravel.url
通过php artisan route:list 可以看到当前应用的路由情况, 在前端页面中如果要修改一个实体,需要用到实体.update,涉及的uri为实体/{实体},所用的http方法为put. ...