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 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- iOS线程数量监控工具
简单却强大的线程监控工具 KKThreadMonitor :当线程过多或瞬间创建大量子线程(线程爆炸),控制台就打印出所有的线程堆栈.便于分析造成子线程过多或线程爆炸的原因. /******* 线程爆 ...
- python圆周率计算小程序(非常慢)
源码: from math import fabs #导入数学模块 from time import perf_counter #导入时间模块 from numba import jit @jit d ...
- ExceptionInChainedOperatorException:flink写hbase对于null数据导致数据导致出现异常
使用的flink版本:1.9.1 异常描述 需求: 从kafka读取一条数据流 经过filter初次筛选符合要求的数据 然后通过map进行一次条件判断再解析.这个这个过程中可能返回null或目标输出o ...
- 从一次“并发修改字段业务”引出多版本并发控制与InnoDB锁
并发字段修改业务 最近在主要在做"工作流引擎"课题的预研工作,在涉及到"会签任务"(工作流业务概念,这与我们今天讨论文问题没有太多关联)的时候,遇到了一个并发修 ...
- Springboot:员工管理之修改员工(十(8))
构建员工修改请求 com\springboot\controller\EmployeeController.java /*调转到员工修改页 携带员工信息 restful风格*/ @GetMapping ...
- 立体匹配-----NCC视差匹配
目录 一.立体匹配算法 1.立体匹配算法分类 二.NCC 视差匹配方法 1.原理 2.NCC计算公式 3.算法流程 4.代码实现 5.不同场景运行 三.结论 四.遇到的问题及解决方法 一.立体 ...
- 一、搭建SpringBoot2.0.0M4基础Web项目
本次开发环境为: 系统:Linux Mint 18 JDK:1.8 开发工具:IntelliJ IDEA 2017.2.4 1.启动IDEA工具,开始创建一个基础项目.点击Create New Pro ...
- 大数据hbase分布式安装及其部署。
大数据hbase分布式安装及其部署. 首先要启动Hadoop以及zookeeper,可以参考前面发布的文章. 将hbase的包上传至master节点 这里我使用的是1.3.6的版本,具体的根据自己的版 ...
- thinkphp5 --接口实例
这是我自己构思的案例,写的不好请多多指教. 后台接口的代码: public function index() { $res = array(); header("Access-Control ...
- 2019-2020-1 20199308《Linux内核原理与分析》第七周作业
<Linux内核分析> 第六章 进程的描述和进程的创建 6.1 进程的描述 操作系统内核实现操作系统的三大管理功能: 进程管理(进程)-核心 内存管理(虚拟内存) 文件系统(文件) 为了管 ...