2017-08-01 21:35:53

writer:pprp

集训第一天:作为第一道题来讲,说了两种算法,

  第一种是跟二进制数联系起来进行分析;

  第二种是用深度搜索来做,虽然接触过深度搜索但是这种题型还是我第一次见;

题目:

  统计1~n之间有多少数字只由0,1构成
  1 ≤ n ≤ 1e9

用深度搜索解决这种问题;


代码如下:

#include <iostream>
#include <map> using namespace std; map<int,int>vis; long long ans = ; int n; //深度搜索,模仿
void dfs(int x)
{
if(x > n)
return;
if(vis[x])
return;
vis[x] = ;
ans++;
dfs(x*);
dfs(x*+);
} int main()
{
cin >> n; dfs(); cout << ans << endl; return ;
}

遇到的问题:不知道为什么用数组来取代map就不能通过,最后还是用了map

Codeforces 9C Hexadecimal's Numbers - 有技巧的枚举的更多相关文章

  1. Codeforce 9C - Hexadecimal's Numbers

    One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got ...

  2. Codeforces Beta Round #9 (Div. 2 Only) C. Hexadecimal's Numbers dfs

    C. Hexadecimal's Numbers 题目连接: http://www.codeforces.com/contest/9/problem/C Description One beautif ...

  3. codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表

    C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...

  4. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  5. C. Hexadecimal's Numbers

    C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...

  6. CodeForces - 1245A Good ol' Numbers Coloring (思维)

    Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...

  7. CodeForces 682A Alyona and Numbers (水题)

    Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...

  8. Codeforces 449D Jzzhu and Numbers

    http://codeforces.com/problemset/problem/449/D 题意:给n个数,求and起来最后为0的集合方案数有多少 思路:考虑容斥,ans=(-1)^k*num(k) ...

  9. 9 C. Hexadecimal's Numbers

    题目链接 http://codeforces.com/contest/9/problem/C 题目大意 输入n,计算出n之内只有0和1组成的数字的数量 分析 k从1开始,只要小于n,就给sum++,并 ...

随机推荐

  1. sql查询用nolock

    大家在写查询时,为了性能,往往会在表后面加一个nolock,或者是with(nolock),其目的就是查询是不锁定表,从而达到提高查询速度的目的. 什么是并发访问:同一时间有多个用户访问同一资源,并发 ...

  2. Codeforces Round #364 (Div. 1)B. Connecting Universities

    题目链接:传送门 题目大意:n个点构成一棵树,给定 k*2 点,要分成 k 组,使每组点之间的距离之和最大. 题目思路:因为是求距离之和最大,所以我们可以知道这样一个性质.如果以一条边为界,两边的子树 ...

  3. iOS 程序切换后台

    1. -(void)animationFinished:(NSString*)animationid finished:(NSNumber*)finished context:(void*)conte ...

  4. Less-css基础扩展

    //扩展Extend less的伪类,合并了选择器,放在与它引用匹配的选择器上 Use Method:以在study上扩展test的样式为例 .test{ color:#000000; font-si ...

  5. 『浅入深出』MySQL 中事务的实现

    在关系型数据库中,事务的重要性不言而喻,只要对数据库稍有了解的人都知道事务具有 ACID 四个基本属性,而我们不知道的可能就是数据库是如何实现这四个属性的:在这篇文章中,我们将对事务的实现进行分析,尝 ...

  6. Exchange Powershell:ForwardingAddress&InboxRule

    查询在邮箱上设置的转发功能: Get-Mailbox -server MX01 -Filter {ForwardingAddress -like '*'} | Select-Object Name, ...

  7. 判断 checkbox 是否选中以及 设置checkbox选中

    //判断checkbox 是否选中 $("#id").is(":checked");//选中,返回true,没选中,返回false //设置checkbox为选 ...

  8. Web 编程中路径问题

    web.xml 中 <url-pattern> 路径(即 Servlet 路径) 要么以 "*" 开头, 要么以 "/" 开头. 转发和包含路径(服 ...

  9. Feature Pyramid Networks for Object Detection

    Feature Pyramid Networks for Object Detection 特征金字塔网络用于目标检测 论文地址:https://arxiv.org/pdf/1612.03144.pd ...

  10. JQuery操作select中的option

    html页面代码例如以下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...