HDU 5587 Array (规律)
来源:互联网 发布:特别想找个女朋友知乎 编辑:程序博客网 时间:2024/06/05 09:51
题意:
话说中文题目里有hint看hint就懂了
第一项永远为数字1,因此样例1输出1
第二天先复制一次,用0隔开,得到1,0,1,再把产生的数字加1,得到1,1,2,因此样例2输出前3项和1+1+2=4.
第三天先得到1,1,2,0,1,1,2,然后得到1,1,2,1,2,2,3,因此样例3输出前5项和1+1+2+1+2=7
分析:
规律很显然,然后二分搜一下
代码:
//// Created by TaoSama on 2015-11-28// 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 = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;typedef long long LL;LL n;LL a[65] = {0, 1}, b[65] = {0, 1}; //total: 54LL dfs(LL n) { if(n <= 0) return 0; if(n == 1) return 1; int idx = upper_bound(a + 1, a + 55, n) - a - 1; return b[idx] + n - a[idx] + dfs(n - a[idx] - 1);}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); for(int i = 2; a[i - 1] <= 1e16; ++i) { a[i] = 2 * a[i - 1] + 1; b[i] = 2 * b[i - 1] + a[i - 1] + 1; } while(t--) { scanf("%I64d", &n); printf("%I64d\n", dfs(n)); } return 0;}
0 0
- HDU 5587 Array (规律)
- HDU 5587 Array 规律+递归
- HDU 5587 Array (找规律_二分)
- HDU 6172 Array Challenge(打表找规律+构造矩阵)
- hdu 5587(数学规律)
- hdu 3184 (规律)
- hdu 1210 (规律)
- hdu (找规律)
- HDU-5587 Array(DFS)
- HDU 5587 Array(递归)
- hdu 5587 Array(高效)
- HDU 6172 Array Challenge 找规律+矩阵快速幂
- hdoj LCP Array 5635 (找规律)
- hdu(4655-打表找规律)
- HDU 1297(大数+规律)
- hdu 2608(找规律)
- hdu 1165(找规律)
- HDU--5312(规律+数学)
- Single Number II
- ccf 字符串匹配
- ActiveMQ和JMS的使用
- recyclerview出现的问题
- 实时搜索引擎Elasticsearch(5)——Java API的使用
- HDU 5587 Array (规律)
- ios之自定义导航栏背景,标题和返回按钮文字颜色
- (php)实现批处理文件以及PHPExcel的实践
- 南大软院大神养成计划--第十三天网页细节处理中
- 工业4.0时代袭来
- 就Share来谈谈一些小看法
- STM32学习第五天---看了CT117E比赛版的硬件结构
- 《Android开发艺术探索》笔记之Activity的生命周期和启动模式
- HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)