【题目链接】: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. win7下UDL文件不同

    win7 执行UDL文件看不全all驱动.所以没有办法配置数据库的连接.查度娘,方法如下: 在C:\建一个test.udl 文件,运行命令 C:\Windows\syswow64\rundll32.e ...

  2. 关于安卓sdk开发环境的的更新-Android SDK下载和更新失败

    由于特别原因,我们更新安卓sdk时不会成功.解决办法: 修改C:\Windows\System32\drivers\etc\hosts文件.添加一行:74.125.237.1       dl-ssl ...

  3. SpringBoot 配置 @ConfigurationProperties 与 @Value 区别

    一.SpringBoot 配置 @ConfigurationProperties 与 @Value 区别 配置文件 yml 还是 properties 他们都能获取到值: 如果说,我们只是在某个业务逻 ...

  4. 从零開始写游戏引擎(一) - project创建以及文件夹设置还有版本号控制

    一句话提要 好的開始等于成功了一半. 创建文件夹结构 project文件夹下最好分为以下几个文件夹 Docs - 开发文档,设计文档 Assets - 角色,动作,模型和音效等 Source - 代码 ...

  5. 定时任务为什么不用Timer

    在做定时任务的时候,有的同学可能能会用到Timer这个定时任务的辅助类, 可是使用它会有潜在的风险,风险例如以下, (1)时间计算不准确问题     由于Timer是以绝对时间计算定时任务的,会受到系 ...

  6. [Angular] Component's dependency injection

    An Angular service registered on the NgModule is globally visible on the entire application. Moreove ...

  7. 回想四叉树LOD地形(上)

           唉.~事实上这是在差点儿相同一年前实现的东西,但当时没作好记录.放了那么久了,假设不做点总结的话,好像有点对不起自己,于是·········还是做点什么吧.        我脑洞比較小, ...

  8. NAT配置

    静态NAT Router(config)#ip nat inside source static tcp 192.168.100.2 61.159.62.131   指定地址转换映射 Router(c ...

  9. DNS隧道工具汇总——补充,还有IP over DNS的工具NSTX、Iodine、DNSCat

    github上有一堆的工具:https://github.com/search?utf8=%E2%9C%93&q=DNS+tunnel+&type= DNS隧道大检阅 研究了一天的DN ...

  10. 蓝桥杯--算法提高 排列数 (简单dfs)

    算法提高 排列数   时间限制:1.0s   内存限制:256.0MB      问题描述 0.1.2三个数字的全排列有六种,按照字母序排列如下: 012.021.102.120.201.210 输入 ...