A. Ehab Fails to Be Thanos

这个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. Ehab Is an Odd Person

这个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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #563 (Div. 2)C

    C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're g ...

  6. 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 ...

  7. Codeforces Round #563 (Div. 2)A

    A. Ehab Fails to Be Thanos 题目链接:http://codeforces.com/contest/1174/problem/A 题目 You’re given an arra ...

  8. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

  9. Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale

    后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...

  10. Codeforces Round 563 (Div. 2) 题解

    自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...

随机推荐

  1. Java 数据类型转换的骚操作和神奇现象

    问:银行用什么数据类型来表示余额?float还是double? 都不是!!下面说明为什么都不可以呢? public static void main(String[] args) { //浮点数他都是 ...

  2. 【Tool】使用IDEA创建简单的Java项目

    IDEA创建简单的Java项目 打开IDEA进入首页面,点击 Create New Project 点选第一项就是了,SDK就是我们的JDK,,这里我已经装好了JDK和JDK的环境变量 IDEA就能自 ...

  3. 绕过XSS过滤姿势总结

    0x01 弹窗关键字检测绕过 基本WAF都针对常用的弹窗函数做了拦截,如alert().prompt().confirm(),另外还有代码执行函数eval(),想要绕过去也比较简单,我们以alert( ...

  4. stand up meeting 1/15/2016 && work of weekend 1/16/2016~1/17/2016

    part 组员                工作              工作耗时/h 明日计划 工作耗时/h    UI 冯晓云  组内对生词卡片又重新进行了讨论:准备最后的发布和整个开发的整理 ...

  5. vue单页应用和和多页应用的区别

    个人见解如下: 单页面应用(SinglePage Web Application  )简称:SPA 多页面应用 (MultiPage Application) 简称:MPA 组成一个外壳和多个页面片段 ...

  6. Linux学习笔记(四)帮助命令

    帮助命令 man info help --help man 英文原意:format and display the on-line manual pages 功能:显示联机帮助手册 语法:man 选项 ...

  7. DOS事件

    1 onblur 失去焦点 2 onchange   改变 3 onkeyup      按键弹起 4 onmouse over 鼠标移上去 5 onmouse leave   鼠标离开 6 onmo ...

  8. testlink数据表分析

    创建一个项目test node_types: 节点类型,这是一个固定的表 rights: 权限表,用户的操作权限 role_rights: 角色和权限关系表 roles: 角色表 testprojec ...

  9. linux常用命令--文件的权限

    ls -lh 显示权限 ls /tmp | pr -T5 -W$COLUMNS 将终端划分成5栏显示 chmod ugo+rwx directory1 设置目录的所有人(u).群组(g)以及其他人(o ...

  10. redis: 配置文件详解(十一)

    #通用配置 bind 127.0.0.1 #绑定可访问的ip 默认本机访问,如果bind选项为空的话,那会接受所有来自于可用网络接口的连接,也可以绑定指定ip访问 protected-mode yes ...