BNUOJ 51003 BQG's Confusing Sequence(二进制)
来源:互联网 发布:安卓新闻推荐 知乎 编辑:程序博客网 时间:2024/06/07 08:56
题意:
混乱数:=只由a和b两种数字构成的正整数,a,b∈[0,9],a≠b
求第1≤n≤109个混乱数是谁,答案对109+7取模
分析:
由于a,b可能为0,先统一情况,把0都去掉
sum[i]:=1∼i混乱数有多少个
然后求到n落在的位数k,再减去之前1∼i−1位的个数
对于含0的情况不减,正好补上那些非法数的个数
然后二进制表示转化成混乱数的十进制表示即可
代码:
//// Created by TaoSama on 2015-12-26// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;typedef long long LL;LL a, b, n;LL digit[50], sum[50];int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif// ios_base::sync_with_stdio(0); int t; scanf("%d", &t); while(t--) { scanf("%lld%lld%lld", &a, &b, &n); if(a > b) swap(a, b); if(a) --n; for(int i = 1; i <= 40; ++i) sum[i] = (1LL << i) - (a ? 0 : (1LL << i - 1)); int k; for(int i = 1; i <= 40; ++i) { sum[i] += sum[i - 1];// prln(sum[i]); if(sum[i] > n) {k = i; break;} } if(a) n -= sum[k - 1];// pr(k); prln(n); int cnt = 0; memset(digit, 0, sizeof digit); for(; n; n >>= 1) digit[++cnt] = n & 1; reverse(digit + 1, digit + k + 1); LL ans = 0; for(int i = 1; i <= k; ++i) {// prln(digit[i]); ans = (ans * 10 + (digit[i] ? b : a)) % MOD; } printf("%lld\n", ans); } return 0;}
破题写了一个小时,debug半天,二进制的功力还是不够高
Q神的代码太6了,比我统一的完美的多
这里去掉最高位是去掉多的部分太吊了,蓝儿并不显然
Q神代码:
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const ll Mod=1000000007LL; int ty[55]; int main() { int T; scanf("%d",&T); while(T--) { int a,b,n; scanf("%d%d%d",&a,&b,&n); if(a>b)swap(a,b); if(a)n++; int loc=0; while(n) { ty[loc++]=n&1; n>>=1; } ll res=0LL; for(int i=loc-1-(a>0);i>=0;i--) res=(res*10+(ty[i] ? b : a))%Mod; printf("%lld\n",res); } return 0; }
0 1
- BNUOJ 51003 BQG's Confusing Sequence(二进制)
- BNUOJ 33993 Stealing Harry Potter's Precious(bfs+dfs)
- Number Sequence (思维,二进制)
- BNUOJ 26192------------King's Poker
- Recaman's Sequence(poj2081)
- Homework (BNUOJ 5134)
- BUPT 652 Confusing Problem(AC自动机+数位DP)
- Confusing Problem
- [SYSU 1800][BNUOJ 27411] Sequence [单调队列][RMQ]
- zoj 2421 Recaman's Sequence(水~)
- POJ 2081 Recaman's Sequence(水题)
- POJ 2081 Recaman's Sequence(水~)
- HDU5288 OO’s Sequence(暴力枚举)
- HDU 5288 OO‘s sequence (技巧)
- HDU 5288 OO’s Sequence(数论)
- HDU5288:OO’s Sequence(思维)
- The confusing state of Microsoft’s TMG and UAG firewall and proxy software
- HPU 1192:Sequence(组合数+二进制选数)
- Android 屏幕适配
- DBCP、C3P0、Proxool 、 BoneCP开源连接池的比较
- Eclipse Debug 教程
- leetcode笔记:Partition List
- linux网络命令--1--ifconfig
- BNUOJ 51003 BQG's Confusing Sequence(二进制)
- 良好的异常展现界面<500.jsp>
- HDU 5602 Black Jack(博弈dp)
- 底部RadioButton实现Fragment切换
- Handler进程之间通信
- Looper类、主线程工作线程通信
- Activity切换中Intent传递数据、对象
- 启动其他Activity并返回结果
- 任务栏 Adobe Acrobat DC / Adobe Reader 图标出错、异常、不显示(Windows下)