Codeforces Round #392 (Div. 2)
16466 단어 ===기초==
A. Holiday Of Equality time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king’s present. The king can only give money, he hasn’t a power to take away them.
Input The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.
The second line contains n integers a1, a2, …, an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.
Output In the only line print the integer S — the minimum number of burles which are had to spend.
Examples input 5 0 1 2 3 4 output 10 input 5 1 1 0 1 1 output 1 input 3 1 3 1 output 4 input 1 12 output 0 Note In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
제목 대의: 전체 서열을 최대수로 바꾸는 데 필요한 차이의 값과 시뮬레이션√
#include
#include
#include
#include
using namespace std;
const int MAXN = 205;
int n,num[MAXN],maxn = 0;
long long ans = 0;
int main()
{
memset(num,0,sizeof(num));
scanf("%d",&n);
if(n <= 1)
{
puts("0");
return 0;
}
for(int i = 1;i <= n; i ++)
scanf("%d",&num[i]),maxn = max(maxn,num[i]);
//
for(int i = 1; i <= n; i ++)
ans += maxn - num[i];
printf("%I64d
",ans);
return 0;
}
B. Blown Garland time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.
Now he has a goal to replace dead light bulbs, however he doesn’t know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.
It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like “RYBGRYBGRY”, “YBGRYBGRYBG”, “BGRYB”, but can not look like “BGRYG”, “YBGRYBYGR” or “BGYBGY”. Letters denote colors: ‘R’ — red, ‘B’ — blue, ‘Y’ — yellow, ‘G’ — green.
Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.
Input The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:
‘R’ — the light bulb is red, ‘B’ — the light bulb is blue, ‘Y’ — the light bulb is yellow, ‘G’ — the light bulb is green, ‘!’ — the light bulb is dead. The string s can not contain other symbols except those five which were described.
It is guaranteed that in the given string at least once there is each of four letters ‘R’, ‘B’, ‘Y’ and ‘G’.
It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line “GRBY!!!B” can not be in the input data.
Output In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.
Examples input RYBGRYBGR output 0 0 0 0 input !RGYB output 0 1 0 0 input !!!!YGRB output 1 1 1 1 input !GB!RG!Y! output 2 1 1 0 Note In the first example there are no dead light bulbs.
In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.
QAQ 이 문제는 영어를 잘 배우는 중요성을 충분히 설명한다. QAQ는 꼬치를 주고 RBGY는 전구의 색깔을 표시한다!!이 전구가 고장나서 바꿔야 한다는 뜻이다. 전체 꿰미는 네 자모로 중복되어 구성되고, BGRYG와 같은 비중복 서열은 비합법적으로 네 가지 색깔의 전구가 각각 몇 개씩 필요한지 계산한다.
시작은 된다!!!!!의 입력은 가능합니다!!!!R!!!!!!Y!!G!!B!!!!!!!!처음에 바보같이 꼬치를 찾으려고 했어요(:з∠) 지적장애 하천구는 사실 네 개의 자모로 이루어진 블록만 중복적으로 나타나는데 RBGYRRBGYR 같은 것은 아니다. 그러면 내 현재 위치는 x, x-4와 x+4의 위치는 반드시 x위치의 자모와 같이 직접적으로 폭력적이면 된다. 어차피 이 자모가 나와야 하는데...//울고 기절한다.
#include
#include
#include
#include
using namespace std;
string s;
int kr = 0,kb = 0,kg = 0,ky = 0;
int len;
void cal(int x)
{
if(s[x] == 'R') kr ++;
if(s[x] == 'Y') ky ++;
if(s[x] == 'B') kb ++;
if(s[x] == 'G') kg ++;
}
int main()
{
cin >> s;
len = s.length();
for(int i = 0; i < len; i ++)
{
if(s[i] == '!')
{
if(i > 3 && s[i - 4] != '!') s[i] = s[i - 4];
else if(i < len - 4 && s[i + 4] != '!') s[i] = s[i + 4];
else
{
int j = i + 4 + 4;
while(j < len)
{
if(s[j] != '!')
{
s[i] = s[j];
break;
}
else j += 4;
}
j = i - 4;
while(j >= 0)
{
if(s[j] != '!')
{
s[i] = s[j];
break;
}
else j -= 4;
}
}
cal(i);
}
}
printf("%d %d %d %d
", kr, kb, ky, kg);
return 0;
}
C. Unfair Poll time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.
Seating in the class looks like a rectangle, where n rows with m pupils in each.
The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, …, the n - 1-st row, the n-th row, the n - 1-st row, …, the 2-nd row, the 1-st row, the 2-nd row, …
The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, …, the m-th pupil.
During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:
the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row.
Input The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).
Output Print three integers:
the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. Examples input 1 3 8 1 1 output 3 2 3 input 4 2 9 4 2 output 2 1 1 input 5 5 25 4 3 output 1 1 1 input 100 100 1000000000000000000 100 100 output 101010101010101 50505050505051 50505050505051 Note The order of asking pupils in the first test:
the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; The order of asking pupils in the second test:
the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table;
이상한 선생님은 이상한 질문 방식을 가지고 있습니다. 첫 번째 줄에서 마지막 줄까지 질문을 하고 다시 질문을 합니다. 첫 번째 질문에서 한 어린 학생이 이렇게 불공평하다고 생각하기 시작했습니다. 그래서 매 시간에 선생님이 가장 많이 질문한 사람과 가장 적은 사람이 각각 몇 번, 그리고 자신이 질문을 받은 사람이 몇 번인지 감동적인 계산을 하기 시작했습니다.
번역에 주의...제목을 알아본 후에도 잘 칠 수 있다//눈을 뜨고 거짓말을 하다
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int MAXN = 205;
ll n,m,k,x,y;//
ll maxn = 0,minn = 1e18 + 7;
ll num[MAXN][MAXN];
ll cal(int i,int j,ll n,ll m,ll k)
{
ll cnt = 0;
if(n == 1)
{
cnt += k / m;
if(j <= k % m) cnt ++;
return cnt;
}
ll ssr = 2 * n * m - 2 * m;
ll hhh = (i - 1) * m + j;
cnt += k / ssr; k %= ssr;
if(i != 1 && i != n)cnt <<= 1;
if(hhh <= k) cnt ++;
if(i == 1 || i == n) return cnt;
i = n - i + 1;
hhh = (i - 1) * m + j;
k -= (n - 1) * m;
if(hhh <= k) cnt ++;
return cnt;
}
int main()
{
scanf("%I64d %I64d %I64d %I64d %I64d",&n,&m,&k,&x,&y);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
num[i][j] = cal(i,j,n,m,k),maxn = max(maxn,num[i][j]),minn = min(minn,num[i][j]);
printf("%I64d %I64d %I64d
",maxn,minn,num[x][y]);
return 0;
}
남은 문제는 못 알아보고 & 못 풀고... (:з∠ Orz 여러분