题目链接: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. SharePoint2010 部署步骤“激活功能”中出现错误:无法启动计算机“PCName”上的服务SPUserCodeV4

    在SharePoint2010开发中,选择部署类型为“部署为沙盒解决方案”,在部署代码是出现如下错误提示: 部署步骤“激活功能”中出现错误:无法启动计算机“PCName”上的服务SPUserCodeV ...

  2. accept系统调用内核实现

    用户态对accept的标准使用方法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_siz ...

  3. 简易的sniffer程序

    真的非常简易,这个程序不过抓一些发送到本机的数据包,然后显示出来它们的一些信息罢了.      程序很easy!       #include <WinSock2.h> #include ...

  4. 高性能C++网络库libtnet实现:Connection

    Connection libtnet只支持IPv4 TCP Connection,之所以这么做都是为了使得实现尽可能的简单.我们主要在Connection类中封装了对tcp连接的操作. Connect ...

  5. treeview树形菜单,递归

    我使用的是递归是实现无限级树形菜单: using System; using System.Collections; using System.Configuration; using System. ...

  6. Js三级联动菜单

    效果演示: <SCRIPT LANGUAGE="JavaScript"> <!-- function CreateSelect(_FormName,_SName, ...

  7. linux配置本地tomcat应用80端口转发

    场景: 本地部署tomcat到8080端口,并期望本地访问80端口来访问本地tomcat. 结论: 使用linux下的iptables工具实现端口转发功能. 具体为 现取得root权限 执行iptab ...

  8. Swift - whose view is not in the window hierarchy 问题解决方法

    问题现象:想在页面初始化的时候,使用self.presentViewController方法弹出个告警提示框UIAlertController.但行后报了个如下告警,同时告警框也出不来. 1 2015 ...

  9. centos7 opera济览器安装

    网网下rpm安装包: http://www.opera.com/computer/thanks?partner=www&par=id%3D39136%26amp;location%3D403& ...

  10. 移植一个开源点餐网到SAE平台上

    记得以前我准备弄个点餐网的,但是由于一些原因没有做下去. 前几天将网上的一个点餐源码移植到了SAE上,网址http://diancan4sae.sinaapp.com. 我想做个外卖网,先选一个学校周 ...