URL 已经复制到剪切板

查看 gist

查看一个gist的详细信息

简介

名称

df21fea5-1d7f-49b0-a2eb-aa0fa8a74f41

创建者

AnonymousUser

创建时间

2018-09-19 13:59

最后修改

2018-09-19 13:59

代码
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> const int maxn = 57; int arr[maxn], bit[maxn]; bool check(int k, int n) { bit[1] = k; for(int j = 0; j <= 20; j ++) { int diff = (arr[2] << j) - (arr[1] << k); int last = (arr[2] << j); bit[2] = j; bool flag = true; for(int i = 3; i <= n; i ++) { if(arr[i] > diff + last) { flag = false; } else { bool find = false; for(int t = 1; t <= 20; t ++) { if((arr[i] << t) == last + diff) { bit[i] = t; find = true; break; } } if(!find) flag = false; last = arr[i] << bit[i]; } } if(flag) return true; } return false; } int main() { int n; std::cin >> n; for(int i = 1; i <= n; i ++) { std::cin >> arr[i]; } int flag = -1; for(int j = 0; j <= 20; j ++) { if(check(j, n)) { flag = j; break; } } for(int i = 1; i <= n; i ++) { printf("%d\n", arr[i] << bit[i]); } }
分享