CodeForces 734F Anton and School
位运算。
两个数的和:$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的更多相关文章
- Codeforces 734F Anton and School(位运算)
[题目链接] http://codeforces.com/problemset/problem/734/F [题目大意] 给出数列b和数列c,求数列a,如果不存在则输出-1 [题解] 我们发现: bi ...
- 【codeforces 734F】Anton and School
[题目链接]:http://codeforces.com/problemset/problem/734/F [题意] 给你两个数组b和c; 然后让你找出一个非负数组a满足题中所给关系; [题解] 有个 ...
- Codeforces 734E. Anton and Tree 搜索
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- [刷题]Codeforces 785D - Anton and School - 2
Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...
- Codeforces 785D - Anton and School - 2 - [范德蒙德恒等式][快速幂+逆元]
题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 ...
- Codeforces 584E - Anton and Ira - [贪心]
题目链接:https://codeforces.com/contest/584/problem/E 题意: 给两个 $1 \sim n$ 的排列 $p,s$,交换 $p_i,p_j$ 两个元素需要花费 ...
- Codeforces 785E. Anton and Permutation
题目链接:http://codeforces.com/problemset/problem/785/E 其实可以CDQ分治... 我们只要用一个数据结构支持单点修改,区间查询比一个数大(小)的数字有多 ...
- Codeforces 734E Anton and Tree(缩点+树的直径)
题目链接: Anton and Tree 题意:给出一棵树由0和1构成,一次操作可以将树上一块相同的数字转换为另一个(0->1 , 1->0),求最少几次操作可以把这棵数转化为只有一个数字 ...
随机推荐
- 转:为什么在定义hashcode时要使用31这个数呢?
散列计算就是计算元素应该放在数组的哪个元素里.准确的说是放到哪个链表里面.按照Java的规则,如果你要想将一个对象放入HashMap中,你的对象的类必须提供hashcode方法,返回一个整数值.比如S ...
- poj 3376 Finding Palindromes
Finding Palindromes http://poj.org/problem?id=3376 Time Limit: 10000MS Memory Limit: 262144K ...
- hdu 2157 How many ways?? ——矩阵十题第八题
Problem Description 春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, ...
- Windows Server 2008 R2 SP1安装SQL 2012安装报错之0x858C001B
使用Windows Server 2008 R2 SP1安装SQL 2012的时候总是报这样一个错: SQL Server Setup has encountered the following er ...
- JS的prototype和__proto__
一.prototype和__proto__的概念 prototype是函数的一个属性(每个函数都有一 个prototype属性),这个属性是一个指针,指向一个对象.它 是显示修改对象的原型的属性. _ ...
- js_实现给未来元素添加事件。
未来元素:不是一个页面上的元素,是通过js或者通过后台直接渲染在页面上的元素,也就是说这些元素不是直接写在document中的. 1.对于未来元素,我们想直接用js或者jq操作它们是不起作用的. $( ...
- AndroidStudio 添加Selector文件,在res文件夹下添加文件夹
在res文件夹下添加文件夹: 添加Selector文件:
- 2.0 docker安装
问题列表: Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again 解:处 ...
- ms17-010 攻击win7漏洞复现
只是为了好玩重新写一篇.利用还是很简单的. 将下载下来的rb放置在:/usr/share/metasploit-framework/modules/exploits/windows/smb/ 目录下 ...
- 最简单的基于FFMPEG的图像编码器(YUV编码为JPEG)(转)
原文转自 https://blog.csdn.net/leixiaohua1020/article/details/25346147/ 伴随着毕业论文的完成,这两天终于腾出了空闲,又有时间搞搞FFMP ...