We have a truck, which can carry at mostN kilograms.
We will load bricks onto this truck, each of which weighsWkilograms. At most how many bricks can be loaded?
Constraints
1≤N,W≤1000
NandWare integers.
Input
Input is given from Standard Input in the following format:
N W
Output
Print an integer representing the maximum number of bricks that can be loaded onto the truck.
풀이
n 킬로그램까지 실을 수 있는 트럭에 w킬로그램 나가는 물건을 얼마나 실을 수 있는지 물어보는 문제이다.
C, C++에서는 그냥 나누면 되고, 파이썬은 정수 나눗셈을 이용한 풀이를 할 수 있다.
정말 쉬운 문제이고, 27초 만에 풀어서 그때 스코어보드 97등이었다. XD
A번 최고기록
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d",a/b);
return 0;
}
[00:27 Accepted]
B. Blocks on Grid
Problem Statement
We have a grid withHhorizontal rows andW vertical columns. The square at thei-th row from the top and j-th column from the left hasAi,jblocks stacked on it.
At least how many blocks must be removed to make all squares have the same number of blocks?
Constraints
1≤H,W≤100
0≤Ai,j≤100
Input
Input is given from Standard Input in the following format:
HW
A1,1A1,2……A1,W
⋮
AH,1AH,2…… AH,W
Output
Print the minimum number of blocks that must be removed.
풀이
모든 블럭의 개수를 체크해서 가장 작은 값으로 만들어야 한다. 따라서 모든 블럭의 개수만큼 반복문을 돌리고, 해당 칸의 블록의 개수에서 가장 적은 블록의 개수를 뺀 것들의 합이 정답이 된다.
#include<stdio.h>
int main()
{
int a,b,min = 99999999,i,j;
int sum=0;
int arr[1001][1001];
scanf("%d%d",&a,&b);
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
scanf("%d",&arr[i][j]);
if(arr[i][j]<min)
{
min = arr[i][j];
}
}
}
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
sum = sum + (arr[i][j]-min);
}
}
printf("%lld",sum);
return 0;
}
업솔빙 한 문제는 년-월-일-시간 순으로 맞은 일시를 적었고, 대회 시간 내 푼 문제는 대회시작으로부터 누적시간-분 순으로 맞은 일시를 적었다.
바로 풀이로 들어가자.
A. Favorite Sequence
Problem statement
Polycarp has a favorite sequencea[1…n]consisting ofnintegers. He wrote it out on the whiteboard as follows:
he wrote the numbera1to the left side (at the beginning of the whiteboard);
he wrote the numbera2to the right side (at the end of the whiteboard);
then as far to the left as possible (but to the right froma1), he wrote the numbera3;
then as far to the right as possible (but to the left froma2), he wrote the numbera4;
Polycarp continued to act as well, until he wrote out the entire sequence on the whiteboard.
The beginning of the result looks like this (of course, if n≥4).
For example, if n=7anda=[3,1,4,1,5,9,2], then Polycarp will write a sequence on the whiteboard[3,4,5,2,9,1,1].
You saw the sequence written on the whiteboard and now you want to restore Polycarp's favorite sequence.
Input
The first line contains a single positive integert(1≤t≤300) — the number of test cases in the test. Then ttest cases follow.
The first line of each test case contains an integern(1≤n≤300) — the length of the sequence written on the whiteboard.
The next line containsnnintegersb1,b2,…,bn(1≤bi≤10^9) — the sequence written on the whiteboard.
Output
Outputtanswers to the test cases. Each answer — is a sequenceathat Polycarp wrote out on the whiteboard.
풀이
문제를 읽으면 알 수 있듯이 처음과 마지막을 먼저 쓰고, 중간을 끝에서부터 순서대로 채워나가는 방식으로 쓴다고 하니 이를 역방향으로 적용시키면 된다. 가장 먼저 첫 element를 출력하고, 그 다음 마지막 element, 2번째, 마지막에서 2번째, ... 이런 식으로 출력을 하자. 이때 n이 홀수인지 짝수인지를 판단해서, 홀수라면 가운데 값이 있으므로 마지막에 따로 출력해 주고, 짝수라면 특이사항이 없다.
#include<stdio.h>
int main()
{
int n;
int arr[1001];
scanf("%d\n",&t);
while(t--){
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d ",&arr[i]);
}
k = n/2;
if(n%2==0){
for(i=0;i<n/2;i++){
printf("%d %d ",arr[i],arr[n-i-1]);
}
printf("\n");
}
else{
for(i=0;i<n/2;i++){
printf("%d %d ",arr[i],arr[n-i-1]);
}
printf("%d\n",arr[n/2]);
}
}
return 0;
}
[00:08 Accepted]
B. Last Year's Substring
Problem statement
Polycarp has a strings[1…n]of lengthnconsisting of decimal digits. Polycarp performs the following operation with the stringsno more than once(i.e. he can perform operation0or1time):
Polycarp selects two numbersiandj(1≤i≤j≤n) and removes characters from thesstring at the positionsi,i+1,i+2,…,j(i.e. removes substrings[i…j]). More formally, Polycarp turns the stringsinto the strings1s2…si−1sj+1sj+2…sn.
For example, the strings="20192020" Polycarp can turn into strings:
"2020" (in this case(i,j)=(3,6)or(i,j)=(1,4));
"2019220" (in this case(i,j)=(6,6));
"020" (in this case(i,j)=(1,5));
other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the stringsinto a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integert (1≤t≤1000) — number of test cases in the test. Thentttest cases follow.
The first line of each test case contains an integern(4≤n≤200) — length of the strings. The next line contains a stringsof lengthnconsisting of decimal digits. It is allowed that the stringsstarts with digit0.
Output
For each test case, output on a separate line:
"YES" if Polycarp can turn the stringssinto a string "2020" in no more than one operation (i.e. he can perform0 or1operation);
"NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the stringsyEs,yes,YesandYESwill all be recognized as positive answer).
풀이
문제를 요약하면 주어진 문자열 안에 '2020'이 1개, 또는 2개로 분리되어 있는지를 판별하는 문제이다. 2020이 1개로 분리되는 방법은 '2020' 한가지밖에 없다. 2개로 분리되는 방법의 수는 '2/020', '20/20', '202/0' 이렇게 3개지 경우가 있다. 하지만 이때 한번만 문자열에서 문자의 묶음을 지울 수 있으므로 '2020'이 2개로 분리되는 경우에서는 분리된 2개의 문자열이 각각 주어진 문자열의 맨 앞과 맨 뒤에 있어야 한다. 앞서 말한 조건을 단순 if문으로 모두 확인하면 된다.
이 문제는 개인적으로 어렵게 생각하면 굉장히 어려워지지만 실제로는 쉬운 문제라고 생각된다.
Editorial을 보기 전 이 문제를 가지고 정말 한참을 고민했는데도 답을 찾지 못했는데, Editorial을 보고 나니 허탈했다;;