1. 程式人生 > 其它 >【CF1463B】Find The Array

【CF1463B】Find The Array

技術標籤:數學

Find The Array

簡介

昨天Educational Round的一題,就是新的數列和原數列的絕對值之差的和小於原數列和的一半,可以考慮構造一個以1為首項2為公比的等比數列,每次都確定小於等於ai的最大值。即2*bi > ai, 這樣就一定可以滿足題目要求。一道數學題。

程式碼

#include <cstdio>
#include <cctype>
#include <cmath>

int t, n;
inline int read(){
    int x = 0; char ch = getchar
(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();} return x; } int main() { t = read(); while (t--){ n = read(); for (int i = 0; i < n; ++i) { int a = read(); int
temp = (int)(log(a) / log(2)); printf("%d ", (int)pow(2, temp)); } printf("\n"); } return 0; }