位运算。

两个数的和:$A+B=(AandB)+(AorB)$,那么$b[i]+c[i]=n*a[i]+suma$。可以解出一组解,然后再按位统计贡献验证一下。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} LL sum,sumc,sumb;
LL t[],g[],a[],b[],c[];
int n; int main()
{
g[]=; for(int i=;i<=;i++) g[i]=g[i-]*;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>b[i];
sumb=sumb+b[i];
} for(int i=;i<=n;i++)
{
cin>>c[i];
sumc=sumc+c[i];
} if((sumb+sumc)%(LL)(*n)!=)
{
printf("-1\n");
return ;
} sum=(sumb+sumc)/(LL)(*n); for(int i=;i<=n;i++)
{
if((b[i]+c[i]-sum)<)
{
printf("-1\n");
return ;
} if((b[i]+c[i]-sum)%(LL)n!=)
{
printf("-1\n");
return ;
} a[i]=(b[i]+c[i]-sum)/(LL)n;
} for(int i=;i<=n;i++)
for(int j=;j<=;j++) if(a[i]&g[j]) t[j]++; bool fail=; for(int i=;i<=n;i++)
{
long long sum=;
for(int j=;j<=;j++) if(a[i]&g[j]) sum=sum+t[j]*g[j];
if(sum!=b[i]) fail=; sum=;
for(int j=;j<=;j++)
{
if(a[i]&g[j]) sum=sum+n*g[j];
else sum=sum+t[j]*g[j];
}
if(sum!=c[i]) fail=;
} if(fail==)
{
for(int i=;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}
else cout<<"-1"<<endl; return ;
}

CodeForces 734F Anton and School的更多相关文章

  1. Codeforces 734F Anton and School(位运算)

    [题目链接] http://codeforces.com/problemset/problem/734/F [题目大意] 给出数列b和数列c,求数列a,如果不存在则输出-1 [题解] 我们发现: bi ...

  2. 【codeforces 734F】Anton and School

    [题目链接]:http://codeforces.com/problemset/problem/734/F [题意] 给你两个数组b和c; 然后让你找出一个非负数组a满足题中所给关系; [题解] 有个 ...

  3. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  4. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  5. [刷题]Codeforces 785D - Anton and School - 2

    Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...

  6. Codeforces 785D - Anton and School - 2 - [范德蒙德恒等式][快速幂+逆元]

    题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 ...

  7. Codeforces 584E - Anton and Ira - [贪心]

    题目链接:https://codeforces.com/contest/584/problem/E 题意: 给两个 $1 \sim n$ 的排列 $p,s$,交换 $p_i,p_j$ 两个元素需要花费 ...

  8. Codeforces 785E. Anton and Permutation

    题目链接:http://codeforces.com/problemset/problem/785/E 其实可以CDQ分治... 我们只要用一个数据结构支持单点修改,区间查询比一个数大(小)的数字有多 ...

  9. Codeforces 734E Anton and Tree(缩点+树的直径)

    题目链接: Anton and Tree 题意:给出一棵树由0和1构成,一次操作可以将树上一块相同的数字转换为另一个(0->1 , 1->0),求最少几次操作可以把这棵数转化为只有一个数字 ...

随机推荐

  1. 前端多层回调问题解决方案之$.Deferred

    javascript引擎是单线程的,但是通过异步回调可以实现IO操作并行执行能力,当业务逻辑复杂的时候我们就进入回调地狱. 本文讲得ajax是在jquery1.5以前的版本,目的旨在让我们理解延迟对象 ...

  2. 51Nod 1004 n^n末尾数字 | 快速幂

    #include "bits/stdc++.h" using namespace std; #define LL long long #define INF 0x3f3f3f3f3 ...

  3. LightOJ 1093 - Ghajini 线段树

    http://www.lightoj.com/volume_showproblem.php?problem=1093 题意:给定序列,问长度为d的区间最大值和最小值得差最大是多少. 思路:可以使用线段 ...

  4. POJ 3087 Shuffle'm Up DFS

    link:http://poj.org/problem?id=3087 题意:给你两串字串(必定偶数长),按照扑克牌那样的洗法(每次从S2堆底中拿第一张,再从S1堆底拿一张放在上面),洗好后的一堆可以 ...

  5. linux shell读取配置文件

    配置文件CoverageInfo FTP_URL=ftp://svn-fb.sicent.com:21/jenkins/Jifei_Repo/OL-2/IDC_Platform/bar_seats_c ...

  6. PHP系统编程--01.多进程与多线程

    PHP中提供了一个扩展pcntl,可以利用操作系统的fork调用来实现多进程.fork调用后执行的代码将是并行的. PHP官方没有提供多线程的扩展,pecl中有一个pthreads扩展提供了多线程的特 ...

  7. 「6月雅礼集训 2017 Day7」回转寿司

    [题目大意] 给一个n个数的序列,q次操作,每次选择区间$[l,r]$,给出数p,对于区间$[l,r]$的每个数$x$,做如下操作: 如果$x > p$,就交换$x$和$p$.求每次操作后$p$ ...

  8. 【BZOJ】1601: [Usaco2008 Oct]灌水

    [算法]最小生成树 [题解] 想到网络流,但是好像不能处理流量和费用的关系. 想到最短路,但好像不能处理重复选边的问题. 每条边只需要选一次,每个点就要遍历到,可以想到最小生成树. 建超级源向每个点连 ...

  9. 回顾一下MyBatis逆向工程——自动生成代码

    前言 最近做的项目(SSM+Shiro)的数据库表已经创建完成,一共有15张表,如果我们一个个去写pojo/bean的代码以及各种sql语句的话未免太过麻烦而且很容易出错,这个时候我们就需要MyBat ...

  10. urllib3使用指南

    对比urllib,用urllib3处理http请求十分方便,可以嵌入web服务后端用于访问其它web实例提供的接口 一.安装 pip install urllib3 二.初始化 导入urllib3 i ...