标签:有关 ati min 任务 两种 info das cts 关联
B - Everyone is a Winner!
On the well-known testing system MathForces, a draw of n rating units is arranged. The rating will be distributed according to the following algorithm: if k participants take part in this event, then the n 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=5 and k=3, then each participant will recieve an 1 rating unit, and also 2 rating units will remain unused. If n=5, and k=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=5, then the answer is equal to the sequence 0,1,2,5. Each of the sequence values (and only them) can be obtained as ⌊n/k⌋ for some positive integer k (where ⌊x⌋ is the value of x rounded down): 0=⌊5/7⌋, 1=⌊5/5⌋, 2=⌊5/2⌋, 5=⌊5/1⌋.
Write a program that, for a given n, finds a sequence of all possible rating increments.
Input
The first line contains integer number t (1≤t≤10) — the number of test cases in the input. Then t test cases follow.
Each line contains an integer n (1≤n≤109) — the total number of the rating units being drawn.
Output
Output the answers for each of t test cases. Each answer should be contained in two lines.
In the first line print a single integer m — the number of different rating increment values that Vasya can get.
In the following line print m integers in ascending order — the values of possible rating increments.
Sample Input
4
5
11
1
3
Sample Output
4
0 1 2 5
6
0 1 2 3 5 11
2
0 1
3
0 1 3
一共有n块钱,k个人[n/k]块钱,向下取整。
现在给你n块钱,你不知道有多少人,输出每个人可能获得多少钱
#include<iostream>
#include<stdio.h>
#include<set>
using namespace std;
int main(){
int t;
cin>>t;
for(int i=1;i<=t;i++){
int n;
cin>>n;
set<int> s;
for(int i=1;i*i<=n;i++){
s.insert(i);
s.insert(n/i);
}
cout<<s.size()+1<<endl;
s.insert(0);
for(auto x:s){
cout<<x<<" ";
}
cout<<endl;
}
}
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int h[15];
int main(){
int t;
cin>>t;
for(int i=1;i<=t;i++){
int ans = 0;
int n;
cin>>n;
map<int,int>A;
map<int,int>B;
for(int i=1;i<=n;i++){
scanf("%d",&h[i]);
A[h[i]]++;
B[h[i]%10]++;
if(A[h[i]]>=2){
ans++;
}
}
cout<<ans<<endl;
for(int i = 1;i<=n;i++){
if(A[h[i]]>=2){
A[h[i]]--;
int g = h[i];
int m1 = g%10; g = g/10;
int m2 = g%10; g = g/10;
int m3 = g%10; g=g/10;
int m4 = g;
for(int j = 0;j<=9;j++){
if(B[j]==0){
B[j]++;
cout<<m4<<m3<<m2<<j<<endl;
break;
}
}
}
else{
printf("%04d\n",h[i]);//保证当第一位为0的情况
}
}
}
}
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.
Input
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.
Output
Print tt integers: the ii-th printed integer is the answer on the ii-th test case in the input.
Example
input
Copy
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
output
Copy
1
2
2
10
5
9
Note
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.
题意:
有 r 个红糖果,g 个绿糖果,b 个蓝糖果,1 <= r,g,b <= 10^8. 每天只能吃两个糖果,问最多可以吃多少天。
思路:
先找出数量最多的哪一种糖果,如果那种糖果的数量大于另外两种糖果的数量之和,则答案必然是另外两种的糖果的数量和,因为即使是每天都吃数量最多的糖果,最后也必然会只剩下哪一种糖果。
如果数量最多的糖果的数量小于等于另外两种糖果数量之和,则输出三者的数量和除以2的结果(小数则向下取整)。因为对于任意满足条件的三个数a,b,c(降序),可以先使a与b配对,剩下的与c配对,最后必然会有c剩下,然后不断拆掉a,b的一对,至c<=1;若a+b+c为奇数,则必然剩下一颗,为偶数则必然全部吃完。
代码:
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll t,a[3];
scanf("%lld",&t);
while(t--){
scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
sort(a,a+3);
if(a[2]>a[0]+a[1])
printf("%lld\n",a[1]+a[0]);
else
printf("%lld\n",(a[0]+a[1]+a[2])/2);
}
return 0;
}
标签:有关 ati min 任务 两种 info das cts 关联
原文地址:https://www.cnblogs.com/lusiqi/p/12040185.html