本文主要是介绍cf Codeforces Round #633 (Div. 2),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A.Filling Diamonds
链接:https://codeforces.com/contest/1339/problem/A
#include <iostream>
#include<bits/stdc++.h>
using namespace std;int main()
{int t;scanf("%d", &t);while(t--){long long x;scanf("%lld", &x);printf("%lld\n", x);}return 0;
}
B. Sorted Adjacent Differences
链接:https://codeforces.com/contest/1339/problem/B
思路:奇数个存放最大的n/2个数(升序),偶数个存放最小的n/2个数(降序),结果就是最后一对是(最大数,最小数)
#include <iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;int a[100010] = {0};
int b[100010] = {0};
int main()
{int T;scanf("%d", &T);while(T--){int n;scanf("%d", &n);memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));for(int i = 1; i <= n; i++)scanf("%d", &a[i]);sort(a + 1, a + n + 1);if(n % 2 == 0){for(int i = 1; i <= n / 2; i++){b[i * 2 - 1] = a[n / 2 + i];}for(int i = 1; i <= n / 2; i++){b[i * 2] = a[n / 2 - i + 1];}}else{for(int i = 1; i <= (n + 1)/ 2; i++){b[i * 2 - 1] = a[n / 2 + i];}for(int i = 1; i <= n / 2; i++){b[i * 2] = a[n / 2 - i + 1];}}for(int i = 1; i <= n; i++){if(i == 1) {}elseprintf(" ");printf("%d", b[i]);}printf("\n");
// for(int i = 1; i < n; i++)//测试代码
// {
//
// if(i == 1) {}
// else
// printf(" ");
// printf("%d", abs(b[i+1] - b[i]));
// }
// printf("\n");}return 0;
}
C题:链接:https://codeforces.com/problemset/problem/1338/A
思路:首先得知道一个定理2的1到k次任意相加可以得到[1,2^(k+1))的所有数字
那么这道题解决起来就很方便了,如果后一个数比前面那个数字小,那么只需要找到x使得2^(x-1)大于差值,根据定理,我们需要x-1秒时间,记录下时间,然后把后一个数的值修改为前面那个数,完成循环之后,对时间取最大即可
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn] = {0};
int main()
{int t;scanf("%d", &t);while(t--){int n, maxn = 0;scanf("%d", &n);memset(a, 0, sizeof(a));for(int i = 1; i <= n; i++){scanf("%d", &a[i]);}for(int i = 2; i <= n; i++){if(a[i] < a[i-1]){//2的1到k次任意相加可以得到[1,2^(k+1))的所有数字int d = a[i-1] - a[i];int t;for(t = 1; t <= 31; t++){if(pow(2, t - 1) > d)//2^x-1 大于差值break;}maxn = max(maxn, t - 1);a[i] = a[i-1];}}printf("%d\n", maxn);}return 0;
}
这篇关于cf Codeforces Round #633 (Div. 2)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!