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),求最少几次操作可以把这棵数转化为只有一个数字 ...
随机推荐
- PostHtml 中的一些有用的插件
记录一下 PostHtml 中的一些比较有用的插件 参考自PostHtml文档 posthtml-pug 将pug转化成html posthtml-md 将md语法转化为html语法 posthtml ...
- 查看自己电脑外网IP
连着wifi,在CMD窗口中显示的无线局域网适配器IP很有可能是内网IP.此时可以通过下面方法查看自己的电脑外网IP. 1.前提条件可以上外网: 2.上外网百度,输入IP,进行搜索. 3.查看结果即可 ...
- 南阳ACM 题目275:队花的烦恼一 Java版
队花的烦恼一 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 ACM队的队花C小+经常抱怨:"C语言中的格式输出中有十六.十.八进制输出,然而却没有二进制输出, ...
- ZooKeeper分层次的法定人数(十二)
分层次的法定人数的介绍 这个文档给出一个关于怎么使用分层次的法定人数的例子.基本思路是很简单的.首先,我们把服务端分组,然后每一组一行.下一步我们分配一个权重为每一个服务端. 下面的例子展示了怎么每组 ...
- (第三章,第四章)http报文内的http信息,返回结果的http状态码
第三章 http报文内的http信息 用于http协议交互的信息被称为http报文,包括请求报文和响应报文. 1.编码提升传输速率,在传输时编码能有效的处理大量的访问请求.但是编码的操作是计算机完成的 ...
- 【BZOJ4816】【SDOI2017】数字表格 [莫比乌斯反演]
数字表格 Time Limit: 50 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description Doris刚刚学习了fibonac ...
- Tomcat8利用Redis配置Session共享
同一个应用在运行多个tomcat实例的时候,经常需要共享Session.tomcat配置共享session有多种方式 1.利用tomcat自身集群特性进行配置: 2.利用Memcache第三方缓存进行 ...
- 【洛谷 P4051】 [JSOI2007]字符加密(后缀数组)
题目链接 两眼题.. 第一眼裸SA 第二眼要复制一倍再跑SA. 一遍过.. #include <cstdio> #include <cstring> #include < ...
- Little Mathematics Knowledge 数学小常识
The sum of arithmetic sequence The sum of geometric sequence A special formula : n·n! = (n+1)! - n! ...
- CART算法(转)
来源:http://www.cnblogs.com/pinard/p/6053344.html 作者:刘建平Pinard 对于C4.5算法,我们也提到了它的不足,比如模型是用较为复杂的熵来度量,使用了 ...