A. Polycarp and Coins
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Polycarp must pay exactly nn burles at the checkout. He has coins of two nominal values: 11 burle and 22 burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.
Thus, Polycarp wants to minimize the difference between the count of coins of 11 burle and 22 burles being used. Help him by determining two non-negative integer values c1c1 and c2c2 which are the number of coins of 11 burle and 22 burles, respectively, so that the total value of that number of coins is exactly nn (i. e. c1+2⋅c2=nc1+2⋅c2=n), and the absolute value of the difference between c1c1 and c2c2 is as little as possible (i. e. you must minimize |c1−c2||c1−c2|).
Input
The first line contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.
Each test case consists of one line. This line contains one integer nn (1≤n≤1091≤n≤109) — the number of burles to be paid by Polycarp.
Output
For each test case, output a separate line containing two integers c1c1 and c2c2 (c1,c2≥0c1,c2≥0) separated by a space where c1c1 is the number of coins of 11 burle and c2c2 is the number of coins of 22 burles. If there are multiple optimal solutions, print any one.
Example
input
6 1000 30 1 32 1000000000 5
output
334 333 10 10 1 0 10 11 333333334 333333333 1 2
Note
The answer for the first test case is "334 333". The sum of the nominal values of all coins is 334⋅1+333⋅2=1000334⋅1+333⋅2=1000, whereas |334−333|=1|334−333|=1. One can't get the better value because if |c1−c2|=0|c1−c2|=0, then c1=c2c1=c2 and c1⋅1+c1⋅2=1000c1⋅1+c1⋅2=1000, but then the value of c1c1 isn't an integer.
The answer for the second test case is "10 10". The sum of the nominal values is 10⋅1+10⋅2=3010⋅1+10⋅2=30 and |10−10|=0|10−10|=0, whereas there's no number having an absolute value less than 00.
题解
分成1和2
就是分成一倍和两倍
所以让n%3
看是哪个多一
n/3即可
#include<iostream>
using namespace std;
int main()
{
long long t;
cin>>t;
while(t--)
{
long long n;
long long a=0,b=0;
cin>>n;
if(n%3==1)
a++;
else if(n%3==2)
b++;
a+=n/3;
b+=n/3;
cout<<a<<" "<<b<<endl;
}
}
B1. Wonderful Coloring - 1
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.
Paul and Mary have a favorite string ss which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a string wonderful if the following conditions are met:
- each letter of the string is either painted in exactly one color (red or green) or isn't painted;
- each two letters which are painted in the same color are different;
- the number of letters painted in red is equal to the number of letters painted in green;
- the number of painted letters of this coloring is maximum among all colorings of the string which meet the first three conditions.
E. g. consider a string ss equal to "kzaaa". One of the wonderful colorings of the string is shown in the figure.
The example of a wonderful coloring of the string "kzaaa".
Paul and Mary want to learn by themselves how to find a wonderful coloring of the string. But they are very young, so they need a hint. Help them find kk — the number of red (or green, these numbers are equal) letters in a wonderful coloring.
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Then tt test cases follow.
Each test case consists of one non-empty string ss which consists of lowercase letters of the Latin alphabet. The number of characters in the string doesn't exceed 5050.
Output
For each test case, output a separate line containing one non-negative integer kk — the number of letters which will be painted in red in a wonderful coloring.
Example
input
Copy
5 kzaaa codeforces archive y xxxxxx
output
Copy
2 5 3 0 1
Note
The first test case contains the string from the statement. One of the wonderful colorings is shown in the figure. There's no wonderful coloring containing 33 or more red letters because the total number of painted symbols will exceed the string's length.
The string from the second test case can be painted as follows. Let's paint the first occurrence of each of the letters "c", "o", "e" in red and the second ones in green. Let's paint the letters "d", "f" in red and "r", "s" in green. So every letter will be painted in red or green, hence the answer better than 55 doesn't exist.
The third test case contains the string of distinct letters, so you can paint any set of characters in red, as long as the size of this set doesn't exceed half of the size of the string and is the maximum possible.
The fourth test case contains a single letter which cannot be painted in red because there will be no letter able to be painted in green.
The fifth test case contains a string of identical letters, so there's no way to paint more than one letter in red.
题解
用map存下每个出现不大于二的字符
然后统计个数
最后除以2即可
#include<iostream>
#include<map>
using namespace std;
int main()
{
int t;
cin>>t;
map<char,int>m;
while(t--)
{
string s;
cin>>s;
int k=0;
for(int i=0;i<s.length();i++)
{
if(m[s[i]]<2)
{
k++;
m[s[i]]++;
}
}
//cout<<k<<endl;
cout<<k/2<<endl;
m.clear();
}
}