Anton and School
2 seconds
256 megabytes
standard input
standard output
Anton goes to school, his favorite lessons are arraystudying. He usually solves all the tasks pretty fast, but this time the teacher gave him a complicated one: given two arrays b and c of length n, find array a, such that:
where a and b means bitwise AND, while a or b means bitwise OR.
Usually Anton is good in arraystudying, but this problem is too hard, so Anton asks you to help.
The first line of the input contains a single integers n (1 ≤ n ≤ 200 000) — the size of arrays b and c.
The second line contains n integers bi (0 ≤ bi ≤ 109) — elements of the array b.
Third line contains n integers ci (0 ≤ ci ≤ 109) — elements of the array c.
If there is no solution, print - 1.
Otherwise, the only line of the output should contain n non-negative integers ai — elements of the array a. If there are multiple possible solutions, you may print any of them.
4
6 8 4 4
16 22 10 10
3 5 1 1
5
8 25 14 7 16
19 6 9 4 25
-1
分析:可以证明答案数组是a[i]=(b[i]+c[i]+Σ(b[i]+c[i])/(2n))/n;
然后根据异或合取性质检验答案;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define freopen freopen("in.txt","r",stdin)
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,t;
ll a[maxn],b[maxn],c[maxn],d[maxn],k[maxn],num[][maxn],sum;
bool flag;
int main()
{
int i,j;
flag=true;
scanf("%d",&n);
rep(i,,n)b[i]=read();
rep(i,,n)c[i]=read();
rep(i,,n)d[i]=b[i]+c[i],sum+=d[i];
sum/=(*n);
rep(i,,n)a[i]=(d[i]-sum)/n;
rep(i,,n)
{
rep(j,,)if((a[i]>>j)&)num[j][i]=,k[j]++;
}
rep(i,,n)
{
ll tmp1=,tmp2=;
rep(j,,)
{
if(num[j][i])tmp1+=(<<j)*k[j];
else tmp2+=(<<j)*k[j];
}
if(tmp1!=b[i]&&tmp2!=c[i])
{
flag=false;
break;
}
}
if(flag)
{
rep(i,,n)printf("%lld ",a[i]);
}
else puts("-1");
//system("Pause");
return ;
}
Anton and School的更多相关文章
- Codeforces 734E. Anton and Tree 搜索
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- Codeforces Round #379 (Div. 2) E. Anton and Tree 缩点 直径
E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a t ...
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- Codeforces Round #379 (Div. 2) A. Anton and Danik 水题
A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟
题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmem ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- Codeforces Round #379 (Div. 2) E. Anton and Tree 树的直径
E. Anton and Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- CSS3的基础知识点
面临找工作之际,又将CSS3的基础知识撸了一把,做了相应的笔记,主要是方便自己查阅,参考的是W3C的知识. 1.CSS背景 (1).background-size 属性 background-s ...
- Apache httpd.conf配置详解
常用配置指令说明 1. ServerRoot:服务器的基础目录,一般来说它将包含conf/和logs/子目录,其它配置文件的相对路径即基于此目录.默认为安装目录,不需更改. 语法:ServerRoot ...
- Linux入门(二)Linux基本命令及基本操作
1 常用Linux命令 图形界面进入到字符界面: ctrl+alt+F2~F6 字符界面进入到图形界面:ctrl +alt+F7 查看本机ip: ifconfig (windows是:ipconf ...
- PHP验证码程序
[摘自网络,参考学习] <?php/** * vCode(m,n,x,y) m个数字 显示大小为n 边宽x 边高y * http://blog.qita.in * 自己改写记录session $ ...
- OpenCV常用函数分析
1. 聚类:将拥有最相似属性的数据归为一类. K-means聚类: python调用格式:compacness, labels, centers = cv2.kmeans(data, K, crite ...
- FZU 1894 志愿者选拔 单调队列
训练赛的题…… 暴力一波明显超时…… 最近刚学stl 感觉是优先队列 但还是太会用…… 以后可以试一下优先队列…… 比赛之后百度了一下 发现是单调队列…… 看起来挺简单的 也算个模版题吧…… 总之思路 ...
- Chapter 15_3 使用环境
创建模块的基本方法的缺点在于,忘记使用local,很容易就污染全局空间. “函数环境”是一种有趣的技术,它能够解决上面的问题.就是让模块的主程序块独占一个环境. 这样不仅它的所有函数可以共享这个tab ...
- wc的用法
wc -c filename:显示一个文件的字节数 wc -m filename:显示一个文件的字符数 wc -l filename:显示一个文件的行数 wc -L filename:显示一个文件中的 ...
- iOS UIScrollview代理方法
方法&&属性: // 监控目前滚动的位置(默认CGPointZero) CGPoint contentOffset; - (void)setContentOffset:(CGPoint ...
- 【报错】java.lang.RuntimeException: Invalid action class configuration that references an unknown class named [xxxAction]
java.lang.RuntimeException: Invalid action class configuration that references an unknown class name ...