A. Ehab Fails to Be Thanos

题意:问你能否对a数组任意排序,使得前n段和不等于后n段和。

思路:水题,直接从小到大排序。这个情况都相等就一定无解。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll n;
ll a[maxn]; int main()
{
n = read();
ll sum1 = 0, sum2 = 0;
rep(i,1,n*2) a[i] = read();
sort(a+1,a+1+n+n);
rep(i,1,n) sum1 += a[i];
rep(i,n+1,n*2) sum2 += a[i];
if(sum1==sum2) cout<<-1<<endl;
else
{
rep(i,1,n*2) cout<<a[i]<<' '; cout<<endl;
}
return 0;
}

B. Ehab Is an Odd Person

题意:若a[i]+a[j]是奇数,就可以调换这两者。这个操作可以做任意多次。问你能构成的最小字典序序列。

思路:因为a[i]+a[j]要是奇数,必须是奇数+偶数的形式才行。而且能发现,其实只要奇数和偶数在a中都有,就可以拿出一个来和任意位置swap,就一定能达到字典序最小。反之就只能输出原序列。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn];
bool vis[maxn]; int main()
{
ll n = read();
int cur = 2;
ll ma = 1;
while(cur<=n)
{
if(vis[cur])
{
cur++;
continue;
}
for(ll i=1; i*cur<=n; i++)
{
if(!vis[i*cur]) a[i*cur] = ma, vis[i*cur] = 1;
}
cur++;
ma++;
}
rep(i,2,n) cout<<a[i]<<' '; cout<<endl;
return 0;
}

C. Ehab and a Special Coloring Problem

题意:让你构造一个从i=2到i=n的序列。其中两下标(i,j)若互质,则a[i]不能等于a[j]。让你使得序列中最大值最小。输出这个序列。

思路:直接看互质不好下手,我们可以在遍历到一个数的时候把它的n内倍数都赋予相同的值,这一步是贪心。那没被筛到的就是和它互质的,自然和它的值不同(每筛一趟要赋值的数就++)。那么外层遍历一遍1->n,内层遍历倍数,为一个调和级数的时间复杂度。总时间复杂度O(n\(\log\)n)。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn];
bool vis[maxn]; int main()
{
ll n = read();
int cur = 2;
ll ma = 1;
while(cur<=n)
{
if(vis[cur])
{
cur++;
continue;
}
for(ll i=1; i*cur<=n; i++)
{
if(!vis[i*cur]) a[i*cur] = ma, vis[i*cur] = 1;
}
cur++;
ma++;
}
rep(i,2,n) cout<<a[i]<<' '; cout<<endl;
return 0;
}

D. Ehab and the Expected XOR Problem

题意:让你构造一个序列,a[i]<\(2^n\),同时任意子段的异或和不等于x或者0。让你输出一个长度最长的符合条件序列。

思路:有一个重要的结论要用到:

若b[i]为a前i个数的异或和。那么a[l]a[l+1]...^a[r] = b[r]^b[l-1]。

所以这个题要任意子段异或和不等于x或者0,就相当于任意b[r]^b[l-1]不等于0或x。

因此我们只需要枚举前缀和,看看到当前这个数的时候如果前缀和是i,会不会有ix这个前缀和已经存在,如果不存在,这个前缀和就合法,这个数就是ipre,pre为当前凑出来的数的前缀和。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e6+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn];
ll vis[maxn]; int main()
{
ll n = read();
ll x = read();
vector<ll> ans;
vis[0] = 1;
ll pre = 0;
for(ll i=1; i<=(1<<n)-1;i ++)
{
if(vis[i^x]) continue;
vis[i] = 1;
ans.pb(i^pre);
pre = i;
}
cout<<ans.size()<<'\n';
for(int i=0; i<ans.size(); i++) cout<<ans[i]<<' '; cout<<endl;
return 0;
}

Codeforces Round #563 (Div. 2) ABCD 题解的更多相关文章

  1. Codeforces Round #315 (Div. 2) (ABCD题解)

    比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...

  2. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  3. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  4. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

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

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  8. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  9. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  10. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

随机推荐

  1. 如何在 Go 中解析 yaml 文件

    Go 语言没有内置解析 yaml 文件的功能,实现 yaml 的解析可以使用第三方库 gopkg.in/yaml.v2 和 gopkg.in/yaml.v3. 下面以解析 config.yml 文件为 ...

  2. DeepSeek在IT运维中的实战应用与价值创新

    DeepSeek在IT运维中的实战应用与价值创新可以从以下几个方面展开分析,结合技术能力.场景适配与商业价值,提供系统化的视角: 一.核心应用场景与实战价值 1. **故障预测与主动防御** - ** ...

  3. Kreuzberg:本地OCR+多格式解析!Kreuzberg如何用Python暴力提取30+文档格式?程序员看完直呼内行!

    嗨,大家好,我是小华同学,关注我们获得"最新.最全.最优质"开源项目和高效工作学习方法 我们经常需要从各种不同类型的文档中提取文本内容,无论是办公文档.图像还是PDF文件.而Kre ...

  4. 电脑ocr软件

    天若ocr 体积小,可以隐藏任务栏,但有时候识别度不好,停止更新了,新项目为树洞ocr github: https://github.com/AnyListen/tianruoocr/releases ...

  5. TDesign腾讯高保真Axure RP中后台交互模板及元件组件库

    TDesign腾讯Axure RP中后台交互模板部件及元件组件库素材基于腾讯TDesign素材库,进行二次创作,并非官网的免费静态版.具体内容,可以看右侧的预览按钮,确认内容. 在线演示及下载:htt ...

  6. 操作系统综合题之“采用实时调度,可调度的限制条件和可调度的最大X值是是多少ms的CPU时间”

    一.问题:单处理器情况下,m个周期性实时进程,若进程i处理时间为Ci,周期时间为Pi < (1 ≤ i ≤ m) 1.要使系统可调度的限制条件什么? 2.设置一个实时系统使用了4个周期事件,其周 ...

  7. C++ 模板实参类型限制

    有时候我们编写一个模板,希望用户使用我们期望的类型来实例化它,就需要对实参进行检查,限制不满足条件的实例化版本,同时给出便于理解的编译时信息. 对于 C++20 后的版本,可以将条件包装为concep ...

  8. eclipse左边窗口再次出现的方法

    1.WindowsShow ViewOtherProject Explorer 2.WindowsShow ViewProject Explorer

  9. React Native开发鸿蒙Next---灰度模式

    React Native开发鸿蒙Next---灰度模式 政企相关的App在开发过程中,往往需要制作一个灰度模式,用于应对注入国家公祭日等特殊日期情况.Harmony开发中,由于基于ArkTs,处理相对 ...

  10. 阅读类元服务开发笔记---week1

    .markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...