https://codeforces.com/contest/1490/problem/B
Problem - B - Codeforces
codeforces.com
[난이도] Div.3
[유형] 구현
[풀이]
크기 3짜리 배열에 나머지가 0,1,2인 숫자들의 개수를 각각 저장 뒤.
index 0,1,2 각각에서 시작해서 N/3만큼만 남기고 순차적으로 우측( a[(i+1)%3] ) 으로
밀어보는 시도를 한다.
최대 2회까지 밀어보고 나머지를 민 타겟의 위치가 N/3이 되게 되면 그때가 최적의 정답이다.
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int tc,n,a[50];
int main(){
scanf("%d",&tc);
while(tc--){
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
int ans = 0;
for(int i=1;i<n;i++){
int p=a[i-1],q=a[i];
if(p>q) swap(p,q);
if(2*p>=q) continue;
int cur=p;
for(int cur=2*p;cur<q;cur*=2){
ans++;
}
}
printf("%d\n",ans);
}
}
https://github.com/has2/Problem-Solving/blob/master/codeforces/Round702-Div.3/B.cpp
'Problem-Solving > Codeforces' 카테고리의 다른 글
[Codeforces][Round #EDU109][Div.2] A : Potion-making (C++) (0) | 2021.05.18 |
---|---|
[Codeforces][Round #702][Div.3] C : Sum of Cubes (C++) (0) | 2021.03.01 |
[Codeforces][Round #702][Div.3] A : Dense Array (0) | 2021.03.01 |
[Codeforces][Round #701][Div.2] B : Replace and Keep Sorted (C++) (0) | 2021.02.14 |
[Codeforces][Round #701][Div.2] A : Add and Divide (C++) (0) | 2021.02.14 |