Codeforces Round #563 (Div. 2) A-D
这个A题很简单,就是排个序,然后看前面n个数和后面的n个数是不是相同,相同就输出-1
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e4 + ;
typedef long long ll;
int a[maxn]; int main()
{
int n;
scanf("%d", &n);
for (int i = ; i <= *n; i++) scanf("%d", &a[i]);
sort(a + , a + + *n);
ll sum1 = , sum2 = ;
for (int i = ; i <= n; i++) sum1 += a[i];
for (int i = n + ; i <= * n; i++) sum2 += a[i];
if (sum1 == sum2) printf("-1\n");
else {
for (int i = ; i <= * n - ; i++) printf("%d ", a[i]);
printf("%d\n", a[ * n]);
}
return ;
}
A
这个B题我写的比C还慢,这个题目有一个规律就是如果这里面既存在奇数又存在偶数,那么就可以排成任意顺序。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e5 + ;
typedef long long ll;
int a[maxn];
int main()
{
int n;
int odd = , even = ;
scanf("%d", &n);
for(int i=;i<=n;i++)
{
scanf("%d", &a[i]);
if (a[i] & ) odd++;
else even++;
}
if(even==||odd==)
{
for (int i = ; i <= n - ; i++) printf("%d ", a[i]);
printf("%d\n", a[n]);
}
else
{
sort(a + , a + + n);
for (int i = ; i < n; i++) printf("%d ", a[i]);
printf("%d\n", a[n]);
}
return ;
}
B
C. Ehab and a Special Coloring Problem
这个C其实比较简单,应该很容易就可以想到用素数筛吧。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e5 + ;
typedef long long ll;
int isp[maxn], v[maxn], m;
void init()
{
for(int i=;i<=maxn;i++)
{
if(v[i]==)
{
isp[m++] = i;
v[i] = i;
}
for(int j=;j<m;j++)
{
if (v[i]<isp[j] || i * isp[j]>maxn) break;
v[i*isp[j]] = isp[j];
}
}
} int vis[maxn];
int a[maxn];
int main()
{
int n, num = ;
scanf("%d", &n);
init();
for(int i=;i<=n;i++)
{
if (vis[v[i]] == ) vis[v[i]] = num++;
a[i] = vis[v[i]];
}
for (int i = ; i < n; i++) printf("%d ", a[i]);
printf("%d\n", a[n]);
return ;
}
C
D. Ehab and the Expected XOR Problem
这个D题我觉得是存在难度的,这个D是一个异或问题,这就要求我们对异或的运算法则十分了解。
这个题目主要有两个限制,一个是小于2的n次方,第二个是既不可以有任意子串的异或值为0也不可以为x
这个我可以想到这些异或运算法则,但是不知道要怎么去处理。
最后看了lj大佬的题解,是用异或前缀和来处理。
首先我们可以知道,如果已知一个数列的异或和,那么我们就可以求出这个数列的每一个数
其次我们可以把从1到(1<<n)这些数字都当作一些数字的异或和,所以呢,
因为任意子串的异或值不可以为0,所以说明不可以有相同的前缀异或和放在一个集合中。
所以我们就分成两个集合,最后判断哪个集合更大输出哪个。
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 5e5 + ;
vector<int>vec[];
int vis[maxn]; int main()
{
int n, x;
scanf("%d%d", &n, &x);
int ex = ( << n);
for(int i=;i<ex;i++)
{
if (i == x) continue;
vis[i] = vis[x^i] ^ ;
vec[vis[i]].push_back(i);
}
int ans = ;
if (vec[].size() > vec[].size()) ans = ;
int len = vec[ans].size();
printf("%d\n", len);
for(int i=;i<len;i++)
{
if (i == ) printf("%d ", vec[ans][i]);
else printf("%d ", vec[ans][i] ^ vec[ans][i - ]);
}
printf("\n");
return ;
}
D
Codeforces Round #563 (Div. 2) A-D的更多相关文章
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem
链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...
- Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person
链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...
- Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos
链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...
- Codeforces Round #563 (Div. 2)C
C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're g ...
- Codeforces Round #563 (Div. 2)B
B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...
- Codeforces Round #563 (Div. 2)A
A. Ehab Fails to Be Thanos 题目链接:http://codeforces.com/contest/1174/problem/A 题目 You’re given an arra ...
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale
后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...
- Codeforces Round 563 (Div. 2) 题解
自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- IDEA默认KeyMap映射快捷键
编辑 快捷键 描述 Ctrl + 空格 基础代码补全(任意类.方法.变量的名字) Ctrl + Shift + 空格 智能代码补全(过滤期望类型的方法和变量列表) Ctrl + Shift + 回车 ...
- AJ学IOS 之小知识之_xcode插件的删除方法_自动提示图片插件KSImageNamed有时不灵_分类或宏之类不能自动提示,
AJ分享,必须精品 一:解决解决自动提示图片插件KSImageNamed有时不灵_分类或宏之类不能自动提示 其实,插件神马的我们自己也能写,并没有想象中的那么难,不过目前我们还是先解决当前问题 在做微 ...
- Shell 变量引用实例
初学 Shell 编程时,对变量各种引用使用不太熟悉,走了很多弯路,本文记录变量引用的一些用法,希望对大家有所帮助. 引用 引用指将字符串用引用符号引起来,以防止特殊字符被 shell 脚本解释为其他 ...
- Extjs——简单的Grid panel小实例
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- python的多线程、多进程、协程用代码详解
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:刘早起早起 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...
- 排序算法代码实现-Java
前言 为了准备面试,从2月开始将排序算法认认真真得刷了一遍,通过看书看视频,实践打代码,还有一部分的leetcode题,自己感觉也有点进步,将笔记记录总结发出来. 冒泡排序 该排序就是一种像泡泡浮到水 ...
- 配置CORS代理请求
参考资料: Vue-CLI 3.x 跨域问题处理 使用代理设置:见官方文档 配置代理 新建配置文件 在 package.json 文件的同级目录下创建 vue.config.js 文件,文件的格式应该 ...
- this 关键字的用法
用法一 this代表当前类的实例对象 class Program { static void Main(string[] args) { tr ...
- C#反射(二)
长时间没有回顾反射知识了,今天就讲解一下反射的一般第二个用法. 二.对方法,属性等的反射 首先需要写一个测试类,生成.exe或.dll文件. class Test { public Test()/ ...
- javascript-文件File转换成base64格式
不能直接访问用户计算机中的文件,一直都是Web应用开发中的一大障碍.2000年以前,处理文件的唯一方式就是在表单中加入<input type="file">字段,仅此而 ...