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 ...
随机推荐
- English trip -- VC(情景课) 6 C Is your class at 11:00? 你的课11点开始吗?
Grammar focus 语法点 Is your class at 11:00 ? # 带be动词的一般疑问句 Yes, it is No, it isn't 相当于 is not Pra ...
- 安卓出现Invalid layout of java.lang.String at value
Project->Properties->Run/Debug setting->选择类->classpath->删除Bootstrap Entries下面的文件 参考
- python-day43--单表查询之关键字执行优先级(重点)
一.关键字的执行优先级(重点) 1.关键字执行优先级 from where #约束条件(在数据产生之前执行) group by #分组 没有分组则默认一组 按照select后的字段取得一张新的虚拟表, ...
- 关于初级dp的一些记忆
01背包和数塔都是寒假看的,数塔还算明白,但01背包虽然会做其实也是背下来的,一直不是很清楚它的可行性,昨天老师讲了以后恍然大悟,和数塔类似生成了一颗二叉树: 利用数组/dfs 自下而上/自上而下 ...
- BUCTOJ1073
#include "iostream" #include "algorithm" using namespace std; ; struct Time { in ...
- Xshell如何设置,当连接断开时保留Session,保留原文字
Xshell [1] 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议.Xshell 通过互联网到远程主机的安全连接以及它 ...
- POJ 1442 splay
前几天用treap写了这一题,不过treap支持的操作不如splay的多,作为一个完美主义者,重新用splay写了这一题. splay大部分操作可以通过 强大到无与伦比的数据结构splay-tree ...
- spring cloud图形化dashboard是如何实现指标的收集展示的
spring cloud图形化dashboard是如何实现指标的收集展示的 1.dashboard图形化界面入口 http://localhost:10000/hystrix.stream 说明:端口 ...
- 超详细:Python(wordcloud+jieba)生成中文词云图
# coding: utf-8 import jieba from scipy.misc import imread # 这是一个处理图像的函数 from wordcloud import WordC ...
- windows创建窗口、关闭窗口流程
NC,即 non-client 区域,包括标题栏.窗口边框.最大.最小按钮.滚动条等. 一.在调用Windows的::CreateWindowEx函数创建窗口时,一般会先发出 WM_NCCREATE消 ...