https://codeforces.com/contest/1490/problem/A
[난이도] Div.3
[유형] Greedy
[풀이]
a[i]와 a[i+1]가 dense가 아니라면 둘중 작은 수에서 두배의 수를 더해가면서 배열에 추가해주면 된다.
#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/A.cpp
'Problem-Solving > Codeforces' 카테고리의 다른 글
[Codeforces][Round #702][Div.3] C : Sum of Cubes (C++) (0) | 2021.03.01 |
---|---|
[Codeforces][Round #702][Div.3] B : Balanced Remainder (C++) (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 |
[Codeforces][Round #693][Div.3] D : Even-Odd Game (C++) (0) | 2021.01.23 |