test20181017 B君的第一题
题意


分析
考场做法
对p的幂打表发现,我们一定可以把x和y的二进制位从低到高依次调整成0。
具体而言,从0次幂开始每两个分为一组a,b,那么0,a,b,a+b组合中的一种可以将x,y的对应二进制位都调整成0。
然后模拟一下就行了。
时间复杂度\(O(\log |x| + \log |y|)\)
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#define rg register
#define il inline
#define co const
#pragma GCC optimize ("O0")
using namespace std;
template<class T> il T read(T&x)
{
T data=0;
int w=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-'0',ch=getchar();
return x=data*w;
}
typedef long long ll;
const int INF=0x7fffffff;
const complex<ll>p(-1,-1);
const int MAXN=1000;
int S[MAXN],cnt;
int main()
{
freopen("guangzhou.in","r",stdin);
freopen("guangzhou.out","w",stdout);
ll x,y;
read(x);read(y);
complex<ll>a(1,0),b(-1,-1),t;
for(int i = 0;x || y;++i,(a *= p) *= p,(b *= p) *= p)
{
// cerr<<"i="<<i<<endl;
// cerr<<"a="<<a<<" b="<<b<<endl;
t = 0;
if( (x & (1LL << i)) == (t.real() & (1LL << i)) && (y & (1LL << i)) == (t.imag() & (1LL << i)) )
{
// cerr<<" case 1"<<endl;
continue;
}
t = a;
if( (x & (1LL << i)) == (t.real() & (1LL << i)) && (y & (1LL << i)) == (t.imag() & (1LL << i)) )
{
// cerr<<" case 2"<<endl;
x -= t.real() ,y -= t.imag();
S[++cnt] = 2 * i;
continue;
}
t = b;
if( (x & (1LL << i)) == (t.real() & (1LL << i)) && (y & (1LL << i)) == (t.imag() & (1LL << i)) )
{
// cerr<<" case 3"<<endl;
x -= t.real() ,y -= t.imag();
S[++cnt] = 2 * i + 1;
continue;
}
t = a + b;
if( (x & (1LL << i)) == (t.real() & (1LL << i)) && (y & (1LL << i)) == (t.imag() & (1LL << i)) )
{
// cerr<<" case 4"<<endl;
x -= t.real() ,y -= t.imag();
S[++cnt] = 2 * i;
S[++cnt] = 2 * i + 1;
continue;
}
}
printf("%d\n",cnt);
for(int i=1;i<=cnt;++i)
{
printf("%d\n",S[i]);
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
标解
跟冬令营2017亿兆京垓 (Radixphi)这道题有关。
像确定二进制一样,每次右移,然后判断最后一位的奇偶,这题可以每次/p,然后判断实部和虚部的和的奇偶。
高斯整数一定能表示成\(-1 \pm i\)进制的形式,这是B君翻维基百科上翻到的。然后就被出成题了。
时间复杂度\(O(\log |x| + \log |y|)\)。
#include <bits/stdc++.h>
using namespace std;
complex<long long> n, p, u;
long long x, y;
int a[200], c, i;
int main() {
freopen("guangzhou.in", "r", stdin);
freopen("guangzhou.out", "w", stdout);
cin >> x >> y;
n = complex<long long>(x, y);
p = complex<long long>(-1, -1);
while (n != complex<long long>(0, 0)) {
if ((n.real() + n.imag()) % 2 != 0) {
a[c++] = i;
n -= complex<long long>(1, 0);
}
n /= p;
i++;
}
printf("%d\n", c);
for (int i = 0; i < c; i++) {
printf("%d\n", a[i]);
}
return 0;
}
test20181017 B君的第一题的更多相关文章
- test20181017 B君的第二题
题意 分析 考场50分 旁边的L君告诉我,求的就是非升子序列的个数,于是写了个树状数组. 但是\(\mod{2333} > 0\)还需要组合数中没有2333的倍数,所以实际上只得了\(a_i \ ...
- test20181018 B君的第一题
题意 分析 考场爆零做法 考虑dp,用\(f(i,j,0/1)\)表示i及其子树中形成j个边连通块的方案数,其中i是否向外连边. \(O(n^3)\),转移方程太复杂就打挂了. #include< ...
- test20181016 B君的第一题
题意 分析 考场爆零做法 考虑位数少的一定更小,高位小的一定更少. 然后计算一定位数下不同数字的个数,然后从高到低依次确定数位. 特例:如果确定的高位的后缀出现了x,那么要把x调整到后缀去,这样一定更 ...
- test20181020 B君的第一题
题意 分析 二次剩余问题. x,y相当于二次方程 \[ x^2-bx+c=0 \mod{p} \] 的两根. 摸意义下的二次方程仍然考虑判别式\(\Delta=b^2-4c\). 它能开根的条件是\( ...
- test20181019 B君的第一题
题意 分析 考场做法同标解. 画图模拟分析发现,无论操作顺序怎样,操作数的奇偶性是不变的. 所以等同求出,以每点为根的操作数奇偶性. 用\(f(x)\)表示x及其子树中的边,包括x到它fa的边,将他们 ...
- [算法 笔记]2014年去哪儿网 开发笔试(续)第一题BUG修正
上一篇的blog地址为:http://www.cnblogs.com/life91/p/3313868.html 这几天又参加了一个家公司的笔试题,在最后的编程题中竟然出现了去哪儿网开发的第一题,也就 ...
- 《学习OpenCV》练习题第五章第一题ab
这道题是载入一幅带有有趣纹理的图像并用不同的模板(窗口,核)大小做高斯模糊(高斯平滑),然后比较用5*5大小的窗口平滑图像两次和用11*11大小的窗口平滑图像一次是否接近相同. 先说下我的做法,a部分 ...
- 《学习OpenCV》练习题第四章第一题b&c
#include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...
- 《学习OpenCV》练习题第四章第一题a
#include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...
随机推荐
- 为tomcat指定jdk
安装好jdk,不配置环境变量 windows平台 在catalina.bat文件和setclasspath.bat文件开头的空白处加上如下两句(指定JDK): \jre linux平台 在catali ...
- mysql查询出来的某一列合并成一个字段
查询所有用户及角色,一个用户会有多个角色 select u.*,sr.* from users u left join sys_user_role sur on sur.userCode=u.id l ...
- DZY Loves Colors CodeForces - 444C (线段树势能分析)
大意:有$n$个格子, 初始$i$位置的颜色为$i$, 美丽值为0, 有两种操作 将区间$[l,r]$内的元素全部改为$x$, 每个元素的美丽值增加$|x-y|$, $y$为未改动时的值 询问区间$[ ...
- 『cs231n』作业3问题1选讲_通过代码理解RNN&图像标注训练
一份不错的作业3资料(含答案) RNN神经元理解 单个RNN神经元行为 括号中表示的是维度 向前传播 def rnn_step_forward(x, prev_h, Wx, Wh, b): " ...
- python-day32--进程--->socker并发
一.进程背景 1.进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 2.进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其他所有 ...
- python-day9-集合数据类型
pythons=['alex','egon','yuanhao','wupeiqi','gangdan','biubiu']linuxs=['wupeiqi','oldboy','gangdan'] ...
- ubuntu计划任务
1.第一次编写计划任务,你输入crontab -l 会报错:no crontab for root 这个解决方法:输入crontab -e 2,第一次编写计划任务的时候你要输入select -edit ...
- Chrome DevTools 的 Sources 调试
在 Chrome 中调试 JS 代码,那你不得不与 Chrome DevTools 的 Sources 面板打交道,所以文章主要通过介绍 Sources 面板上的各部分功能来介绍如何调试网页中的 JS ...
- Socket编程基础篇
Socket又称"套接字",应用程序通常通过“套接字”向网络发生请求或者应答网络请求. Socket和ServerSocket类库位于java.net包中,ServerSocket ...
- 55. 45. Jump Game II *HARD*
1. Given an array of non-negative integers, you are initially positioned at the first index of the a ...