A. Candies

题意

给定一个整数,判断是否存在

思路

先对公式进行预处理 明显是一个等比数列
化简后得到

因为答案一定存在 所以用快速幂从小到大枚举即可

#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#include<utility>
#include<deque>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
#define mem(n,a) memset(n,a,sizeof(n))
#define rep(i,be,en) for(int i=be;i<=en;++i)
#define pre(i,be,en) for(int i=en;i>=be;--i)
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 100010;LL quick_pow(int a, int b) {int ans = 1;while (b) {if (b & 1)ans *= a;a *= a;b >>= 1;}return ans;
}
int main() {int t;cin >> t;while (t--) {int n;cin >> n;for (int i = 2;i <= 32;++i) {int t = quick_pow(2, i) - 1;if (n % t == 0) {printf("%d\n", n / t);break;}}}return 0;
}

B. Balanced Array

题意

构造一个长度为n的数列,n为偶数,使得前 个数全为偶数
个数全为奇数
并且使前后区间和相等

思路

观察样例可知 n/2为奇数时不能构造出来
n/2为偶数时 对前面的偶数按顺序构造,后面的n/2-1个奇数也按顺序构造,用最后一个奇数补足与偶数和的差值使前后区间和相等
容易知道最后一个奇数应该为

#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#include<utility>
#include<deque>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
#define mem(n,a) memset(n,a,sizeof(n))
#define rep(i,be,en) for(int i=be;i<=en;++i)
#define pre(i,be,en) for(int i=en;i>=be;--i)
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 100010;int main() {int t;cin >> t;while (t--) {int n;cin >> n;if ((n / 2) & 1)puts("NO");else {puts("YES");int t = 2;for (int i = 1;i <= n / 2; ++i)printf("%d ", t), t += 2;t = 1;for (int i = 1;i <= n / 2 - 1; ++i)printf("%d ", t), t += 2;printf("%d\n", n / 2 - 1 + n);}}return 0;
}

C. Alternating Subsequence

题意

从给定序列中选择一个正负交替的子序列使得子序列的和最大

思路

双指针,每次扫过一个正负号相同的区间,找到区间的最大值作为子序列的元素

#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#include<utility>
#include<deque>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
#define mem(n,a) memset(n,a,sizeof(n))
#define rep(i,be,en) for(int i=be;i<=en;++i)
#define pre(i,be,en) for(int i=en;i>=be;--i)
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 200010;int a[N];int np(int a) {if (a < 0)return 1;else return 2;
}int main() {int t;cin >> t;while (t--) {int n;cin >> n;for (int i = 1;i <= n;++i)cin >> a[i];LL ans = 0;int s, p, maxn;p = 1;while (p <= n) {s = p;maxn = a[p];while (np(a[s]) == np(a[p]) && p <= n) {maxn = max(maxn, a[p]);++p;}ans += maxn;}cout << ans << endl;}return 0;
}

D. Constant Palindrome Sum

题意

给一个长度为n的数列和一个k 要求用不大于k的数替换数组中的任意一个数 使 所有关于数组对称的两个位置的元素和相等 即      问最少替换多少次

思路

刚开始我想先算出每两个数对的和出现次数最多的当作x 再根据x与其他组数对的大小计算答案 后来发现这种方法是不可行的 因为每个数对和都不一样的情况是可能出现的 这时候无法判断到底选哪个作为x更合适
后来 看到别人的博客 才想起来下面这种方法
即 算出每个数对的和 并且记录该数对每一个x的贡献 再选择一个最小的当作答案
很容易分情况讨论
minn = min(a[i], a[n - i + 1])
maxn = max(a[i], a[n - i + 1])
t = a[i] + a[n - i + 1]
delta代表差分数组
因为数组元素的范围是 [1,k]
所以数对的取值范围为 [2,2*k]
①x取 [2,minn] 时 即使较大的那个数改成了1 还是不符合这个范围 所以需要两个都改变
②x取 [minn + 1,maxn + k] 时,只需要改变其中一个数字即可
③x取 [maxn + k + 1, 2 * k] 时,两个都需要改变
④因为当数对和为x时 不需要改变任何一个数字 而第二部已经把这种情况包括了 所以需要减去 即 delta[x]–

#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#include<utility>
#include<deque>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define eps 1e-6
#define mem(n,a) memset(n,a,sizeof(n))
#define rep(i,be,en) for(int i=be;i<=en;++i)
#define pre(i,be,en) for(int i=en;i>=be;--i)
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lowbit(int x) { return x & -x; }using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 200010;int a[N], delta[N << 1];int main() {int t;cin >> t;while (t--) {memset(delta, 0, sizeof delta);int n, k;cin >> n >> k;for (int i = 1;i <= n;++i)cin >> a[i];for (int i = 1;i <= n / 2;++i) {int t = a[i] + a[n - i + 1];int minn = min(a[i], a[n - i + 1]);int maxn = max(a[i], a[n - i + 1]);delta[2] += 2;delta[minn + 1] -= 2;delta[maxn + k + 1] += 2;delta[2 * k + 1] -= 2;delta[minn + 1] ++;delta[maxn + k + 1]--;delta[x]--;delta[x + 1]++;}LL ans = INF;for (int i = 2;i <= 2 * k;++i) {delta[i] += delta[i - 1];ans = min(ans, (LL)delta[i]);}cout << ans << endl;}return 0;
}

Codeforces Round #636 (Div. 3) A-D相关推荐

  1. Codeforces Round #636 (Div. 3) F. Restore the Permutation by Sorted Segments 思维 + 暴力

    传送门 文章目录 题意: 思路: 题意: n≤200n\le200n≤200 思路: 首先关注到rrr从[2,n][2,n][2,n]都出现一次,所以很明显最后一个位置只出现一次,但是这样倒着来不是很 ...

  2. Codeforces Round #636 (Div. 3) E. Weights Distributing 思维 + bfs

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5 思路: 怎么感觉每场div3div3div3都有一个巧妙的图论题. 首先如果只有两 ...

  3. Codeforces Round #636 (Div. 3) D. Constant Palindrome Sum 思维 + 差分

    传送门 文章目录 题意: 思路: 题意: 思路: 首先有一个显然的性质就是每组操作最多不会超过两次. 很容易想到一个很暴力的思路,就是枚举x∈[1,2∗k]x \in [1,2*k]x∈[1,2∗k] ...

  4. Codeforces Round #636 (Div. 3)部分题解

    链接:Codeforces Round #636 (Div. 3) A - Candies 题意:求出一个x满足x+2∗x+4∗x+⋯+2k−1∗x=n且k>1 思路:提出x得x∗(1+2+4+ ...

  5. Codeforces Round #636 (Div. 3)

    Codeforces Round #636 (Div. 3)(2020.4.21) A.Candies 因为题目保证了有解,所以我们枚举一下 k k k就行了. #include <bits/s ...

  6. Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum

    Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum 题目链接 You are given an array a consisting of ...

  7. Codeforces Round #636 (Div. 3) C.Alternating Subsequence

    Codeforces Round #636 (Div. 3) C.Alternating Subsequence 题目链接 Recall that the sequence b is a a subs ...

  8. Codeforces Round #636 (Div. 3)(ABC)

    A. Candies 水题,暴力即可 代码如下: #include<bits/stdc++.h> #define ll long long using namespace std;int ...

  9. Codeforces Round #636 (Div. 3) ——A. Candies 题解

    题目链接:https://codeforces.com/contest/1343/problem/A 签到题,for循环暴力枚举即可. 代码如下: #include <bits/stdc++.h ...

  10. Codeforces Round #636 (Div. 3)D. Constant Palindrome Sum

    传送门-链接 题意:输入一个n和k,第二行输入一个长度为n的数组a,且保证了n为一个偶数,数组a中的每一个元素都不大于k,你可以修改多次,使得a[i]+a[n-i+1]=x(x为某个确定的值),你需要 ...

最新文章

  1. python计算生态的命名_Python计算生态之random库
  2. C++手册_迅为干货 | C程序调用shell
  3. 关于 paddingFactor 及 COLLMOD 的设置值
  4. 微信小程序php get_php处理微信小程序request请求
  5. WebStorm 8.0.3下简单运行pomelo项目
  6. 在内核中如何获得系统的日期和时间
  7. java创建gitlab账户_GitLab不会创建新的存储库
  8. Linux中log打印输入输出的格式字符串
  9. u9系统的使用方法仓库_用友ERP系统,U9操作流程图
  10. 使用python编程数学建模-Python的特点及优缺点(课程1)
  11. delphi mysql5_Delphi7连接MySql5.5.15
  12. 脑电和脑磁图的非线性动力学分析
  13. 计算机属性资源管理器已停止工作,Win7资源管理器老是停止工作怎么办?资源管理器已停止工作解决方法...
  14. vbox android wifi,virtualbox桥接无线网卡实现上网
  15. unity导入FBX模型时出现材质丢失,模型为白膜的情况
  16. 只要五分钟,让你成功接入Twitter的第三方登录
  17. 商城 商品模块 数据库 表设计
  18. java Locale介绍
  19. 计算机安全被动攻击的技术手段,2020年9月网络教育统考《计算机应用基础》计算机安全模拟题试卷3...
  20. android7.1系统集成高德地图

热门文章

  1. 造物主的存在与人工智能
  2. 使用kindeditor插件报editor is not defined 问题
  3. 08-Web APIs
  4. [译]Deeper and Wider Siamese Networks for Real-Time Visual Tracking--翻译
  5. VMware vSphere 6 Enterprise Plus 注册码
  6. 亿图脑图协同版全面升级,团队协作更高效!
  7. 2021 新标准大学英语综合教程3 第二版 答案 Unit6 西电研究生B类综合英语
  8. 配置Mondrian源码
  9. 松雅旅馆(实验三第二题)
  10. Genymotion