hdu-5587 Array(回溯)
题目链接:
Array
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/131072 K (Java/Others)
One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle '0' to separat.
Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
Vicky wonders after 100 days, what is the sum of the first M numbers.
First line contains a single integer T, means the number of test cases.(1≤T≤2∗103)
Next T line contains, each line contains one interger M. (1≤M≤1016)
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=1e4+;
const int maxn=; LL dp[],L[],ans,sum[];
void Init()
{
dp[]=;
L[]=;
for(int i=;i<;++i)
{
dp[i]=*dp[i-]+L[i-]+;
L[i]=*L[i-]+;
}
} void dfs(LL x)
{
if(x<=)return;
for(int i=;i<;i++)
{
if(L[i]<=x&&L[i+]>x)
{
ans+=dp[i];
x-=L[i]+;
ans+=x+;
break;
}
}
dfs(x);
}
int main()
{
int t;
read(t);
LL m;
Init();
while(t--)
{
ans=;
read(m);
dfs(m);
printf("%lld\n",ans);
} return ;
}
hdu-5587 Array(回溯)的更多相关文章
- hdu 5587 Array
题目链接:hdu 5587 前两周 bc 上的题了,因为赶大作业所以没有去打,看了下官方给出的思路,感觉好强大~~竟然能转化成求二进制数 1 的个数: 然后数位 dp 就行了, #include< ...
- hdu 5587 Array 数学题
Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5587 De ...
- hdu 5587 Array 二分
Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem ...
- HDU 5587——Array——————【规律】
Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Sub ...
- 2019年CCPC网络赛 HDU 6703 array【权值线段树】
题目大意:给出一个n个元素的数组A,A中所有元素都是不重复的[1,n].有两种操作:1.将pos位置的元素+1e72.查询不属于[1,r]中的最小的>=k的值.强制在线. 题解因为数组中的值唯一 ...
- HDU 5587:Array
Array Accepts: 118 Submissions: 232 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/ ...
- HDU 6197 array array array 2017沈阳网络赛 LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...
- hdu 6197 array array array
array array array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2017多校第10场 HDU 6172 Array Challenge 猜公式,矩阵幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172 题意:如题. 解法: #include <bits/stdc++.h> using ...
随机推荐
- JdkDynamicAopProxy源码
JdkDynamicAopProxy是通过接口实现动态代理类,主要方法是getProxy(ClassLoader classLoader), 代理类生成之后再调用目标方法时就会调用invoke方法. ...
- strlen与sizeof的区别 [转]
转自:http://www.cppblog.com/liangbo/archive/2006/10/06/13394.html 1.sizeof操作符的结果类型是size_t,它在头文件中typede ...
- 7. 泛化(Generalization)
什么是泛化关系?用一个例子简单的说:假设A是B和C的父类,B.C具有公共类(父类)A,说明A是B.C的一般化(概括,也称泛化),B.C是A的特殊化. 在编程上,泛化关系(Generalization) ...
- codis3.1集群搭建
Codis31搭建 codis 3.1 安装搭建 一.基本信息 1. 服务器基本信息 ip地址 安装服务 172.16.200.71 zk1.codis-dashboard.codis-fe.codi ...
- Windows Server 2012远程刷新客户端组策略,IE代理设置
Windows Server 2012远程刷新客户端组策略: 1.PowerShell命令对单台计算机进行刷新: Invoke-GPUpdate -RandomDelayInMinutes 0 -Co ...
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The y ...
- Educational Codeforces Round 4 A. The Text Splitting 水题
A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...
- ubuntu完美卸载JDK
要删除 OpenJDK (如果已安装的话).首先,检查是安装的哪个 OpenJDK包. # dpkg --list | grep -i jdk 移除 openjdk包: # apt-get purge ...
- sql server常用知识点
--删除表 use [20130823_Recource] go drop table my_table1,my_table2,My_table3 --创建表 use [20130823_Recour ...
- 使用Linux的mail命令发送邮件
由于经常工作在linux下,所以很多时候需要将自己工作的报告或其他有用的东东发送给相关的人,所以花时间研究了一下在linux下如何发送mail.我们通常能用到下面3中发送方式: 1. 使用Shell当 ...