Codeforces 9C Hexadecimal's Numbers - 有技巧的枚举
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 - 有技巧的枚举的更多相关文章
- Codeforce 9C - Hexadecimal's Numbers
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got ...
- 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 ...
- 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 ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- C. Hexadecimal's Numbers
C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...
- Codeforces 449D Jzzhu and Numbers
http://codeforces.com/problemset/problem/449/D 题意:给n个数,求and起来最后为0的集合方案数有多少 思路:考虑容斥,ans=(-1)^k*num(k) ...
- 9 C. Hexadecimal's Numbers
题目链接 http://codeforces.com/contest/9/problem/C 题目大意 输入n,计算出n之内只有0和1组成的数字的数量 分析 k从1开始,只要小于n,就给sum++,并 ...
随机推荐
- 【BZOJ3190】[JLOI2013]赛车 单调栈+几何
[BZOJ3190][JLOI2013]赛车 Description 这里有一辆赛车比赛正在进行,赛场上一共有N辆车,分别称为个g1,g2……gn.赛道是一条无限长的直线.最初,gi位于距离起跑线前进 ...
- 移动APP自动化测试框架
简介 移动APP的UI自动化测试长久以来一直是一个难点,难点在于UI的”变”, 变化导致自动化用例的大量维护.从分层测试的角度,自动化测试应该逐层进行.最大量实现自动化测试的应该是单元测试,最容易实现 ...
- JavaScript 学习(2)表单元素
##JavaScript 学习-2 1. 表单和表单元素 1.1 form对象 form对象的引用:document.forms[0]或者引用name属性,如:document.forms[" ...
- 创建view,保存GROUP_CONCAT数据
create view user_account_view asSELECT u.userId UserId ,u.userCode UserCode,GROUP_CONCAT(ac.id) Acco ...
- Duilib 入门级教程 推荐
http://www.cnblogs.com/Alberl/category/520438.html 作者写的不错,图文并茂,适合刚入门.
- vue-cli注册全局组件
在main.js开头引入组件,然后注册组件,例如: import Vue from 'vue' import VueRouter from 'vue-router' import VueResourc ...
- python通过原生sql查询数据库(共享类库)
#!/usr/bin/python # -*- coding: UTF-8 -*- """DB共享类库""" # 使用此类,先实例化一个Da ...
- 【零基础学习iOS开发】【02-C语言】08-基本运算
一.算术运算符 算术运算符很地简单.就是小学数学里面的一些加减乘除操作.只是呢.还是有一些语法细节须要注意的. 1.加法运算符 + 1 int a = 10; 2 3 int b = a + 5; 在 ...
- What is tail-recursion
Consider a simple function that adds the first N integers. (e.g. sum(5) = 1 + 2 + 3 + 4 + 5 = 15). H ...
- 安全技能树简版 正式发布——BY 余弦(知道创宇)
之前留意到知道创宇发布的<知道创宇研发技能表>,对自己有很大的启发,最近听说知道创宇的余弦大神创业了(题外话),还发布了<安全技能树简版V1>,仔细研读之后总体感觉不那么复杂了 ...