题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4151

题意:找出比n小的没有重复数字的总个数,例如12以内11不符合,1~10都符合。

分析:直接利用lower_bound函数找出比n刚好大的位置再减一就是答案。这里a数组从0开始,所以不用减一。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 1<<30
#define N 10000000
using namespace std;
int a[],tot;
int vis[];
void init()
{
tot=;
for(int i=;i<=N;i++)
{
int temp=i;
memset(vis,,sizeof(vis));
while(temp)
{
int t=temp%;
if(!vis[t])vis[t]=;
else break;
temp/=;
}
if(!temp)a[tot++]=i;
}
}
int main()
{
int n;
init();
while(scanf("%d",&n)>)
{
// printf("%d\n",lower_bound(a,a+tot,n)-a);
int left=,right=tot,ans=;
while(left<right)
{
int mid=left+(right-left)/;
if(a[mid]>=n)
{
right=mid;
}
else left=mid+;
}
printf("%d\n",right);
}
}

hdu4151(二分)的更多相关文章

  1. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  2. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  3. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  4. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  5. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  6. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

  7. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

  8. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

  9. BZOJ 3110 [Zjoi2013]K大数查询 ——整体二分

    [题目分析] 整体二分显而易见. 自己YY了一下用树状数组区间修改,区间查询的操作. 又因为一个字母调了一下午. 貌似树状数组并不需要清空,可以用一个指针来维护,可以少一个log 懒得写了. [代码] ...

随机推荐

  1. Windows Azure入门教学系列 (六):使用Table Storage

    本文是Windows Azure入门教学的第六篇文章. 本文将会介绍如何使用Table Storage.Table Storage提供给我们一个云端的表格结构.我们可以把他想象为XML文件或者是一个轻 ...

  2. perl uri_escape(urlencode ) 转换

    [root@wx03 lib]# cat a1.pl #引入模块 use URI::Escape; #urlencode $encoded = uri_escape("[中均]") ...

  3. [Boost基础]并发编程——asio网络库——定时器deadline_timer

    asio库基于操作系统提供的异步机制,采用前摄器设计模式(Proactor)实现了可移植的异步(或者同步)IO操作,而且并不要求使用多线程和锁定,有些的避免了多线程编程带来的诸多有害副作用(如条件竞争 ...

  4. Java批量生成Mac地址到文件

    public class Main { public static void main(String[] args) { // 生成文件名称 String filePath = "mac.t ...

  5. 【实战】静默安装-oracle 11.2.0.3 on centos 5.10

    发现网上静默安装的文章非常多,乱七八糟,五花八门!来个扫盲的!   centos 5.10 下安装oracle 11g_r2 ************************************* ...

  6. 浅谈sqlldr

    1.安装oracle  sqlldr 2.配置sqlldr环境 3java代码的实现 在windows下面sqlldr: sqlldr = “cmd /c start  D:/oracle/produ ...

  7. 几本不错的CPU设计以及VLSI的书籍

    1. Microprocessor Design Principales and Practrices with VHDL  特点:电路与VHDL一一对应,比较清楚,而且还用MAX+plus进行仿真 ...

  8. Flex Label自动截取、自动换行

    label.maxDisplayedLines=0;      // 默认多行显示,不截取 label.maxDisplayedLines=1;     //任意整数,显示单行文本,自动截取(...) ...

  9. 积累的VC编程小技巧之滚动条

    1.设置滚动条的滚动大小 创建一个基于CScrollview的SDI Project(在第6步中选CScrollview) 若你已创建了,这步可以省略. 然后: 改为如 void CTestView: ...

  10. Linux入门基础#2:Linux文件系统基本结构

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...