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. 类 文件 右下角呈现 红色小圆圈,里面有一个J 标记

    intellj(idea) 项目中类 文件 右下角呈现 红色小圆圈,里面有一个J 标记,表明此为 未设置为源文件,没有编译,本来应该是属于源文件的,结果现在没有被标记为源文件,也就没法编译了.

  2. 关于《Python自动化测试实战》

    作者有话说 笔者写这本书的初心是想通过自身经验分享一些在自动化测试领域中的实用技术,能够帮助那些正在从事自动化测试相关工作或者准备转型自动化测试的测试人员.任何一门技术涵盖的知识点都是非常广泛的,可能 ...

  3. [算法]素数筛法(埃氏筛法&线性筛法)

    目录 一.素数筛的定义 二.埃氏筛法(Eratosthenes筛法) 三.线性筛法 四.一个性质 一.素数筛的定义 给定一个整数n,求出[1,n]之间的所有质数(素数),这样的问题为素数筛(素数的筛选 ...

  4. matlab计算相对功率

    1.对脑电数据进行db4四层分解,因为脑电频率是在0-64HZ,分层后如图所示, 细节分量[d1 d2 d3 d4] 近似分量[a4] 重建细节分量和近似分量,然后计算对应频段得相对功率谱,重建出来得 ...

  5. win7下delphi中的help文档问题

    一,要安装WinHlp32.exe 文件 二, 三,在安装目录下:

  6. 植物大战僵尸的代码如何使用python来实现

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:程序IT圈 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...

  7. L26 使用卷积及循环神经网络进行文本分类

    文本情感分类 文本分类是自然语言处理的一个常见任务,它把一段不定长的文本序列变换为文本的类别.本节关注它的一个子问题:使用文本情感分类来分析文本作者的情绪.这个问题也叫情感分析,并有着广泛的应用. 同 ...

  8. L9循环神经网络进阶 ModernRNN

    GRU RNN存在的问题:梯度较容易出现衰减或爆炸(BPTT) ⻔控循环神经⽹络:捕捉时间序列中时间步距离较⼤的依赖关系 RNN: Ht=ϕ(XtWxh+Ht−1Whh+bh) H_{t} = ϕ(X ...

  9. Laravel - 基础

    1.使用 composer 创建项目 composer create-project --prefer-dist laravel/laravel blog 报错1 [ErrorException]pr ...

  10. PHP文件包含漏洞(利用phpinfo)复现

    0x01 简介 PHP文件包含漏洞中,如果找不到可以包含的文件,我们可以通过包含临时文件的方法来getshell.因为临时文件名是随机的,如果目标网站上存在phpinfo,则可以通过phpinfo来获 ...