Codeforces Round #603 (Div. 2)
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 good understanding of the meaning of problems, and his party were given the number of candy in three colors. You can only eat two candy, candy colors and the two can not be the same. Q. How many days up to eat (candy may not be entirely finished, but every day should be strictly in accordance with the rules)
For a, b, c first from small to large.
If a + b <c, it is clear that, like the output of a + b
For a + b> = c. (A + b + c) / 2 this point must fall on b, then we make the point about pairing part of it, is a total of (a + b + c) / 2, and more out of it does not matter.
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main() { int t; cin>>t; while(t--) { int a[3]; int sum = 0; for(int i = 0 ; i<3 ;i++) { cin>>a[i]; sum+=a[i]; } sort(a,a+3); if(a[0]+a[1]<a[2]) cout<<a[0]+a[1]<<endl; else cout<<sum/2<<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 2. 1. 5 . 6 0 2. 3. 5. 11. 1 2 0. 1 . 3 0. 1. 3
meaning of problems, that is, to n, which is divided into parts to k. Each is n / k. For example, a sample:
n = 5: 1 2 3 4 5 6
5 2 1 1 1 0
0 1 2 5: the output
I made our first look at the range of n, 1e9, violent words will timeout (chicken dish T a) we look, for example, for a sample, the results are 1, 4, 5, but we can only output a 1, there is no way to traverse
from n = 3 to 6 directly, skipping repeat item it?
For a sample, 5/3 == 1 and 5/1 == 5, i.e., i = 5, n is exactly divisible, then we let I 3 == skip to i == 6 like
3 are a place n / i == 1 occurs, skip directly to i == 3 i == 6, next a jump i divisible, can skip repeat answer because if n% i == 0, then n / (i + 1) and the results must be n / (i) is not the same
specific codes to see it, just review the vector iterator knock law .....
#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(0); for(int i=1,j;i<=n;i=j+1) { 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; } }