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 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- http的请求头都有那些信息
每个HTTP请求和响应都会带有相应的头部信息.默认情况下,在发送XHR请求的同时,还会发送下列头部信息: Accept:浏览器能够处理的内容类型 Accept-Charset:浏览器能够显示的字符集 ...
- Python openpyxl使用操作和openpyxl操作
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取htt ...
- 嘿嘿,我就知道面试官接下来要问我 ConcurrentHashMap 底层原理了,看我怎么秀他
前言 上篇文章介绍了 HashMap 源码后,在博客平台广受好评,让本来己经不打算更新这个系列的我,仿佛被打了一顿鸡血.真的,被读者认可的感觉,就是这么奇妙. 然后,有读者希望我能出一版 Concur ...
- 曹工说Redis源码(7)-- redis server 的周期执行任务,到底要做些啥
文章导航 Redis源码系列的初衷,是帮助我们更好地理解Redis,更懂Redis,而怎么才能懂,光看是不够的,建议跟着下面的这一篇,把环境搭建起来,后续可以自己阅读源码,或者跟着我这边一起阅读.由于 ...
- Django开发文档-域用户集成登录
项目概述: 一般在企业中,用户以WINDOWS的域用户统一的管理,所以以Django快速开发的应用,不得不集成AD域登录. 网上一般采用django-python3-ldap的库来做集成登录,但是本方 ...
- Linux下nginx自启动配置
1.在linux系统的/etc/init.d/目录下创建nginx文件 vim /etc/init.d/nginx 在脚本中添加一下命令(内容主要参考官方文档) #!/bin/sh # # nginx ...
- SMTP发邮件(直接可用)实例
string file = "邮件测试.txt";//放在Debug下的一个txt文件. MailAddress from = new MailAddress("自己的邮 ...
- 从零开始建图床 minio
图床 图床可以参考知乎这篇文章 一些小众图床有空空间免费,但不知道什么时候会挂掉.前些年用过的极简图床,现在也销声匿迹: 大厂提供的有限免费空间,七牛云10G空间,10Gb/月 流量免费:但如果使用h ...
- 干货最实用的 Python 多线程代码框架
前言 很多地方都要用到多线程,这是我经常用的多线程代码,放在博客园记录下. 代码 from multiprocessing.pool import ThreadPool thread = 10 ite ...
- Java面试系列第3篇-HashMap相关面试题
HashMap是非线程安全的,如果想要用线程安全的map,可使用同步的HashTable或通过Collections.synchronizeMap(hashMap)让HashMap变的同步,或者使用并 ...