codeforces 734F (数学)
来源:互联网 发布:网站权限数据库设计 编辑:程序博客网 时间:2024/05/17 22:59
题目链接:点击这里
题意:给出两个数组b,c,构造a数组满足条件.
首先需要知道一个推论:
这么一个n元1次方程解出来也很容易,然后就是带入按位check, 按照
#include <cstdio>#include <iostream>#include <cstring>#include <queue>#include <cmath>#include <algorithm>#include <stack>#define Clear(x,y) memset (x,y,sizeof(x))#define Close() ios::sync_with_stdio(0)#define Open() freopen ("more.in", "r", stdin)#define fi first#define se second#define pii pair<int, int>#define pli pair<long long, int>#define pb push_back#define mod 1000000007template <class T>inline bool scan (T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; //EOF while (c != '-' && (c < '0' || c > '9') ) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; return 1;}using namespace std;#define maxn 200005long long b[maxn], c[maxn], f[maxn], a[maxn], ans[maxn];int n;int main () { //Open (); Close (); cin >> n; for (int i = 1; i <= n; i++) cin >> b[i]; long long sum = 0; for (int i = 1; i <= n; i++) { cin >> c[i]; f[i] = b[i]+c[i]; sum += f[i]; } a[1] = (f[1]*2*n-sum); if (a[1]%(1LL*2*n*n) != 0) { cout << "-1" << endl; return 0; } a[1] /= (1LL*2*n*n); ans[1] = a[1]; if (a[1] < 0) { cout << -1 << endl; return 0; } for (int i = 2; i <= n; i++) { if ((f[i]-f[1])%n != 0) { cout << -1 << endl; return 0; } a[i] = a[1]+(f[i]-f[1])/n; if (a[i] < 0) { cout << -1 << endl; return 0; } ans[i] = a[i]; } for (int bit = 1; bit <= 33; bit++) { int num = 0; for (int i = 1; i <= n; i++) { num += (a[i]&1); } for (int i = 1; i <= n; i++) { if (a[i]&1) b[i] -= num, c[i] -= n; else c[i] -= num; if ((b[i]&1) || (c[i]&1)) { cout << -1 << endl; return 0; } b[i] >>= 1; c[i] >>= 1; } for (int i = 1; i <= n; i++) a[i] >>= 1; } for (int i = 1; i <= n; i++) cout << ans[i] << " "; cout <<endl; return 0;}
0 0
- codeforces 734F (数学)
- codeforces 698F 数学
- codeforces 852F Product transformation(数学)
- Codeforces Gym 100589F Count Ways(DP+组合数学)
- CodeForces 630 F. Selection of Personnel(组合数学)
- CodeForces - 630F Selection of Personnel (组合数学)
- CodeForces 630F-Selection of Personnel【组合数学】
- Codeforces Round #392 (Div. 2) F. Geometrical Progression(数学)
- Codeforces 659F F
- CODEFORCES 734F Anton and School
- Codeforces Round #379 (Div. 2) F Anton and School(数学)
- Codeforces gym 100548 F (2014-2015 icpc西安现场赛) 数学
- 数学F - The Snail
- 【codeforces】数学
- 【codeforces】数学
- 数学(Anton and School,cf 734F)
- Codeforces 234 F. Fence
- 【Codeforces 500F】Dp
- 第一篇--安装编译环境
- linux内核模块怎么编译——Makefile解析
- 39级台阶问题
- iOS开发-低版本XCode如何支持高版本iOS系统进行真机调试
- 第二篇--下载Android源码
- codeforces 734F (数学)
- 正则表达式(基础篇)
- Android 微信支付死活不走回调问题解决
- iOS KVO的运用理解
- Android如何导入外部已存在的数据库文件(附源码)
- css模块化及CSS Modules使用详解
- 线程间通信
- html2canvas截屏传入后台
- 码云git TortoiseGit SSH配置