CodeForces - 1339E Perfect Triples(打表找规律)
题目链接:点击查看
题目大意:序列 s 是一个无限数列,现在给出构造方法:
- 选择三个数 a b c ,将其依次加到序列 s 的最后面,三个数需要满足:
- a b c 在序列 s 中均未出现过
- a b c 是字典序最小的数列
- a ^ b ^ c = 0
现在给出一个 n ( <= 1e16 ) ,求出数列的第 n 项
题目分析:乍一看可能没什么思路,不过看起来可以打表,于是打表观察一下,打表代码放在最后
打出表后可以发现,以 a b c 为整体的数对被分成了好几大段,每一段的长度分别为 1,4,16,64....4^n,其中在每一大段中,a 都是依次增大的,这是一个比较明显的规律
因为这是对于异或的操作,所以将所有数都转换为二进制再看一看,会发现 b 和 a 有着某种微妙的关系,仔细观察观察或者大胆猜想一下,可以知道这个与四进制有关
将所有数转换为四进制后,就能看出 a 与 b 其中的相同位上:
- a == 0 时 b =0
- a == 1 时 b = 2
- a == 2 时 b = 3
- a == 3 时 b = 1
这样就能在知道 n 的基础上,求出第 n 个数的行与列的坐标,然后求出 a 和 b ,根据 a^b^c=0,得到 c=a^b,这样就能求出答案了
代码:
AC代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<unordered_map>
using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=1e5+100;const int b[]={0,2,3,1};LL get_num1(LL x)
{LL base=1;while(base<x){x-=base;base<<=2;}return base+x-1;
}LL get_num2(LL x)
{LL num1=get_num1(x);LL ans=0;for(int i=0;i<=60;i+=2)ans+=(1LL<<i)*b[(num1>>i)%4];return ans;
}int main()
{
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);int w;cin>>w;while(w--){LL n;scanf("%lld",&n);LL row=(n-1)/3+1;int col=(n-1)%3;LL num1=get_num1(row);LL num2=get_num2(row);LL num3=num1^num2;if(col==0)printf("%lld\n",num1);else if(col==1)printf("%lld\n",num2);elseprintf("%lld\n",num3);}return 0;
}
打表代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<unordered_map>
using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=1e5+100;bool vis[N];void print(int num)//输出四进制
{string ans;for(int i=1;i<=5;i++){ans+=to_string(num%4);num/=4;}reverse(ans.begin(),ans.end());cout<<ans<<' ';
}int main()
{
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);for(int k=1;k<=100;k++){for(int i=1;i<=1000;i++){if(!vis[i]){for(int j=i+1;j<=1000;j++){if(!vis[j]&&!vis[i^j]){vis[i]=vis[j]=vis[i^j]=true;printf("%d %d %d ",i,j,i^j);print(i),print(j),print(i^j);puts("");goto end;}}}}end:;}return 0;
}
CodeForces - 1339E Perfect Triples(打表找规律)相关推荐
- CodeForces - 1110C-Meaningless Operation(打表找规律)
Can the greatest common divisor and bitwise operations have anything in common? It is time to answer ...
- D. Pythagorean Triples(1487D)(打表找规律 + 二分)
D. Pythagorean Triples(1487D)(打表找规律 + 二分) 题目来源:D. Pythagorean Triples 题意: 给定一个 n,求满足以下条件的数对 (a, b, c ...
- [codeforces 1327E] Count The Blocks 打表找规律+根据规律找公式+优化公式
Educational Codeforces Round 84 (Rated for Div. 2) 比赛人数13522 [codeforces 1327E] Count The Blocks ...
- CodeForces - Insertion Sort(打表找规律)
题目链接:http://codeforces.com/gym/101955/problem/C Time limit:6.0 s Memory limit:1024 MB Problem Descri ...
- 点分治问题 ----------- P3727 曼哈顿计划E[点分治+博弈SG函数打表找规律]
题目链接 解题思路: 1.首先对于每个操作我们实际上是一个博弈问题 对于k=1的操作就是很基础的NIM游戏就是找到一条链的异或和为0 对于k=2的操作通过达打表找规律: 如果s是奇数那么偶数的SG函数 ...
- CodeForces - 603C Lieges of Legendre(博弈+找规律)
题目链接:点击查看 题目大意:首先给出n堆石子和一个k值,两人轮流按照规则操作,不能操作的一方即为失败,每一次都有两种操作: 从任意一堆石子中取走一个石子 任选一堆偶数个的石子,将其转换成k堆x/2的 ...
- Yet Another Meme Problem(打表找规律)
Try guessing the statement from this picture http://tiny.cc/ogyoiz. You are given two integers AA an ...
- hdu_5894_hannnnah_j’s Biological Test(打表找规律)
题目链接:hdu_5894_hannnnah_j's Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...
- Ural 2045. Richness of words 打表找规律
2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...
最新文章
- trigger自动执行事件
- 实时流处理框架Storm、Spark Streaming、Samza、Flink,孰优孰劣?!
- 入门Java要学习的一些基本和高级工具
- Python编程习惯
- docker安装ubuntu镜像
- html单选框+点击取消选中,【前端JS】radio 可单选可点击取消选中
- 望图知意-Yahoo VS 3721
- mysql一张表可以用吗_MySQL表操作
- ASP.NET Core MVC 打造一个简单的图书馆管理系统 (修正版)(三)密码修改以及密码重置...
- Java 11 究竟比 8 快了多少?
- 整车控制器(VCU)开发 之 概述
- python pyplot 宽高等比_matplotlib(等单位长度):长宽比为“等”时,z轴不等于x轴和y轴...
- 从子页面获取父页面的值
- Arduino(5) 使用Mega2560设计上下位机串口通信系统的下位机
- 【原创】我所认识的银行业务之旅(账务篇)
- 2022.7.14 花旗银行外包面试
- android中contains的用法
- 【转载】浮华背后与我的路
- linux宝塔计划任务脚本内容怎么写,宝塔Linux面板计划任务按秒数执行脚本
- kotlin中mainactivity无法直接调用xml中的控件_个推TechDay广州站:使用Kotlin演进安卓开发生态...