【题目链接】:http://codeforces.com/problemset/problem/734/F

【题意】



给你两个数组b和c;

然后让你找出一个非负数组a满足题中所给关系;

【题解】



有个结论吧;

(x and y + x or y)=x+y

然后把那n个式子全都加起来;

令d[i]=b[i]+c[i]···①;



d[i]=n∗a[i]+∑a⋅⋅⋅②

再把所有的①式加起来;

∑d=2∗n∑a⋅⋅⋅③

则由③式可得

∑a=∑d/(2∗n)

再代入②式

a[i]=(d[i]−∑d/(2∗n))/n



a[i]=(2∗n∗d[i]−∑d)/(2∗n2)

对于a[i]<0或a[i]不为整数的情况.

返回无解就好;

但是做完这些还不够;

还是可能错解..

还要验证一下得到的a[i]是不是能够按照那个规则得到b[i]和c[i];

但是直接强算是O(N2)的复杂度;

这里一位一位的算比较快;

我们算出所有的aj在第i位上上为1的个数kj;

然后就有





这里看我们可以通过Ai,j和kj快速获取Bi,j和Ci,j





然后根据得到的Ci,j和Bi,j;

根据位权,乘上相应的2的x次方;

然后累加起来;

看看c数组和b数组和所给的c、b数组是否相同.



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100; int n;
LL b[N],c[N],d[N],sumd = 0,a[N],ans[N];
int B[N][65],C[N][65];
LL bin[65]; void out()
{
cout << -1 << endl;
exit(0);
} int main()
{
//Open();
Close();//scanf,puts,printf not use
bin[0] = 1;
rep1(i,1,62)
bin[i] = bin[i-1]<<1;
cin >> n;
rep1(i,1,n)
cin >> b[i];
rep1(i,1,n)
{
cin >> c[i];
d[i] = b[i]+c[i];
sumd += d[i];
}
rep1(i,1,n)
{
a[i] = 1LL*2*n*d[i]-sumd;
LL temp = 1LL*2*n*n;
if (a[i]%temp!=0) out();
a[i]/=temp;
if (a[i]<0) out();
ans[i] = a[i];
}
LL ma = *max_element(a+1,a+1+n);
int limit = 0;
while (ma)
{
ma>>=1;
limit++;
}
rep1(i,0,limit-1)
{
int k = 0;
rep1(j,1,n)
if (a[j]&bin[i])
k++;
rep1(j,1,n)
{
if (a[j]&bin[i])
{
B[j][i]+=k,C[j][i]+=n;
}
else
//a[j]%1==0
C[j][i]+=k;
}
}
rep1(i,1,n)
{
LL tb = 0;
rep1(j,0,limit-1)
tb = tb+B[i][j]*bin[j];
LL tc = 0;
rep1(j,0,limit-1)
tc = tc+C[i][j]*bin[j];
if (tb!=b[i]||tc!=c[i])
out();
}
rep1(i,1,n)
cout << ans[i] <<' ';
//init??????
return 0;
}

【codeforces 734F】Anton and School的更多相关文章

  1. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【13.77%】【codeforces 734C】Anton and Making Potions

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【77.39%】【codeforces 734A】Anton and Danik

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【25.00%】【codeforces 584E】Anton and Ira

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  8. 【codeforces 785E】Anton and Permutation

    [题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...

  9. 【codeforces 785D】Anton and School - 2

    [题目链接]:http://codeforces.com/contest/785/problem/D [题意] 给你一个长度为n的括号序列; 让你删掉若干个括号之后,整个序列变成前x个括号为左括号,后 ...

随机推荐

  1. Emgu cv人脸检测识别

    Emgu cv人脸检测识别 1.开发平台:WIN10 X64    VS2012    Emgucv版本:3.1 2.先给大家分享一个官网给的示例源代码: https://ncu.dl.sourcef ...

  2. 使用maven服务器插件 运行项目

    使用jetty插件  部署运行 创建一个maven项目:去Maven仓库中寻找jetty插件  然后复制到pom.xml中 使用命令  运行程序: 然后控制台打印: 通过浏览器   访问: ----- ...

  3. 流媒体播放器VLC SDL

    http://www.cnblogs.com/lihuixian001/archive/2013/03/15/2957103.html https://wiki.videolan.org/Win32C ...

  4. osEye.Net:离别是为了将来的重逢

    这一时刻已经成为osEye历史..... 在热心网友的关怀和鼓励之下,osEye.net将继续运行着,感谢你们陪伴osEye一起走过.... 与你相知相恋已经有4个年头了,你的成长到成熟都让我历历在目 ...

  5. 浅析C++绑定到Lua的方法

    注:原文也在公司内部论坛上发了  概述       尽管将C++对象绑定到Lua已经有tolua++(Cocos2d-x 3.0用的就是这个).LuaBridge(我们游戏client对这个库进行了改 ...

  6. C++实现位数组

    当我们遇到大量整数排序时候为了节省内存空间我们能够考虑使用bit数组来实现,缺点是其仅仅适用于正整数. 思想: 在32位系统一个int类型占4个字节,按位来计算一个int类型能够记录32个数.因此,採 ...

  7. 2015.05.15,外语,学习笔记-《Word Power Made Easy》 02 “如何谈论医生”

    包括Sessions 4-6: Prefix Person,nous,etc. Practice,etc. Adjective internus内部 internist [ɪn'tɝnɪst] n.内 ...

  8. Gretna2.0 使用过程中遇到的问题

    在做Normalize的时候,报错"Cannot find T1 image (e.g. *.dcm in T1 Directory), Please Check again!", ...

  9. Java-MyBatis: MyBatis3 | Java API

    ylbtech-Java-MyBatis:  MyBatis3 | Java API 1.返回顶部 1. Java API 既然你已经知道如何配置 MyBatis 和创建映射文件,你就已经准备好来提升 ...

  10. 算法入门经典第七章 例题7-2-1 生成1-n的排列

    输入正数n,按字典序从小到大的顺序输出n个数的所有排列.两个序列的字典序大小关系等价于从头开始第一个不相同位置处的大小关系. 递归的边界应该很好理解吧,当集合s[]中没有一个元素的时候,按照上面的伪码 ...