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 ...
随机推荐
- php 8小时时间差的解决方法小结
原来从php5.1.0开始,php.ini里加入了date.timezone这个选项,默认情况下是关闭的 也就是显示的时间(无论用什么php命令)都是格林威治标准时间 和我们的时间(北京时间)差了正好 ...
- Phonetics: Lecture Three 语音 第三课 Teacher:Patrick
元音字母: [u] put [pʊt] push [pʊʃ] full [fʊl] sugar ['ʃʊgɚ] cook [kʊk] look [lʊk] took [tʊk] (v ...
- English trip -- VC(情景课)3 B Bamily members
xu言: 今天,好困啊 -__-. . zZ 早点睡吧...适当的休息,才能更好的学习 Vocabulary focus husband wife uncle aunt brother sister ...
- php--------删除数组的第一个元素和最后一个元素
对于一个php数组,该如何删除该数组的第一个元素或者最后一个元素呢?其实这两个过程都可以通过php自带的函数 array_pop 和 array_shift 来完成,下面就具体介绍一下如何来操作. ( ...
- python-day12--函数进阶
1.命名空间: 分三种:全局命名空间,局部命名空间,内置命名空间. 加载顺序:内置命名空间→全局命名空间→局部命名空间 取值顺序:局部命名空间→全局命名空间→内置命名空间 2.作用域: 作用域就是作用 ...
- Oracle 11g dataguard check RTA(real time apply)
Oracle 11g dataguard check RTA(real time apply) 2017年8月24日 16:38 环境:oracle 11.2.0.1 OEL 5.8 注:以下操作都在 ...
- Quartz定时任务和IIS程序池闲置超时时间冲突解决方案
一.问题描述 Bs项目中用Quartz功能执行一个定时任务(每隔5分钟执行一个Job),正常情况,Quartz定时任务会5分钟执行一次,但IIS程序池闲置 超时默认为20分钟,造成的结果是:定时任务只 ...
- SDL检查
在用 Visual Studio 编译比较早的代码时,经常会遇到错误: 错误 C4996 'wcscpy': This function or variable may be unsafe. Cons ...
- SSH框架下载地址
Struts各版本下载地址: https://dist.apache.org/repos/dist/release/struts/ Spring各版本下载地址: http://repo.spring. ...
- 坏消息:百度影音、快播关闭P2P服务器!
继日前优酷土豆集团.搜狐视频.腾讯视频.乐视网.中国电影著作权协会(MPA).美国电影协会 (MPAA).日本内容产品流通海外促进机构(CODA).万达影业.光线传媒.乐视影业联合发布“中国网络视频反 ...