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 ...
随机推荐
- CentOS Redhat Linux安装 Oracle Client 的注意点
1) 安装文件要拷贝到本地文件系统执行 2) 虽然不知道 libXmu是什么,但是安装之后,关联包安装了许多,感觉很省心 yum install libXmu.i686 3) 还有找不到的包的话,用 ...
- C#两种数据类型
C#的两种类据类型:值类型和引用类型 什么是值类型,什么是引用类型 概念:值类型直接存储其值,而引用类型存储对其值的引用.部署:托管堆上部署了所有引用类型. 引用类型:基类为Objcet 值类型: ...
- Linux : 密码正确不能正常登陆,日志提示Could not get shadow information for user
今天,再玩Centos7的时候,尝试修改了下ssh的端口.因为默认开启了SELinux,如果没有修改这个文件配置就修改端口sshd服务就不能正常启动了. 但是,当我修改会22端口的时候还是不能正常登陆 ...
- English trip -- Phonics 3 元音字母e
xu言: 额...今天给我上自然拼读的maple老师 - . -和上次给我上第二集自然拼读的是同一个老师.突然考了考我上次学的内容~感觉大脑一片空白.看来review不能光说而不下苦功夫啊... 元音 ...
- CentOS 7 install Nginx
1. rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.r ...
- ubuntu安装环境软件全文档
1,安装apace2: sudo apt-get install apache2 2谷歌浏览器的安装:sudo apt-get install chromium-browser-dbg 3,国际版Q ...
- hdu 1069 DAG加权
题目: Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- nyoj1248(阅读理解???)
海岛争霸 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己 ...
- Java容器——Set接口
1.定义 set中不允许放入重复的元素(元素相同时只取一个).它使用equals()方法进行比较,如果返回true,两个对象的HashCode值也应该相等. 2.方法 TreeSet中常用的方法: b ...
- Linux文件与目录管理(一)
一.Linux文件与目录管理 1.Linux的目录结构是树状结构,最顶级的目录是根目录/(用"/"表示) 2.Linux目录结构图: /bin:bin是Binary的缩写,这个目录 ...