Binary Watch

描述

Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary digits to display minutes (00 - 59).

For example 11:26 is displayed as 01011:011010.

Given a number x, output all times in human-readable format "hh:mm" when exactly x digits are 1.

输入

An integer x. (0 ≤ x ≤ 9)

输出

All times in increasing order.

样例输入
  1. 1
样例输出
  1. 00:01
  2. 00:02
  3. 00:04
  4. 00:08
  5. 00:16
  6. 00:32
  7. 01:00
  8. 02:00
  9. 04:00
  10. 08:00
  11. 16:00
    分析:数据范围很小,暴力即可;
    代码:
  1. #include <cstdio>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cstring>
  6. #define rep(i,m,n) for(i=m;i<=n;i++)
  7. #define pii pair<int,int>
  8. #define fi first
  9. #define se second
  10. const int maxn=3e4+;
  11. using namespace std;
  12. int n,m;
  13. int work(int a,int b)
  14. {
  15. int cnt=;
  16. while(a)
  17. {
  18. if(a&)cnt++;
  19. a>>=;
  20. }
  21. while(b)
  22. {
  23. if(b&)cnt++;
  24. b>>=;
  25. }
  26. return cnt;
  27. }
  28. int main()
  29. {
  30. int i,j,k,t;
  31. scanf("%d",&n);
  32. rep(i,,)rep(j,,)
  33. {
  34. if(work(i,j)==n)printf("%02d:%02d\n",i,j);
  35. }
  36. //system("pause");
  37. return ;
  38. }
  1.  

Binary Watch的更多相关文章

  1. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  2. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

  3. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  4. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  5. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  6. Leetcode: Convert sorted list to binary search tree (No. 109)

    Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...

  7. Leetcode, construct binary tree from inorder and post order traversal

    Sept. 13, 2015 Spent more than a few hours to work on the leetcode problem, and my favorite blogs ab ...

  8. [LeetCode] Binary Watch 二进制表

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...

  9. [LeetCode] Find Leaves of Binary Tree 找二叉树的叶节点

    Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps un ...

  10. [LeetCode] Verify Preorder Serialization of a Binary Tree 验证二叉树的先序序列化

    One way to serialize a binary tree is to use pre-oder traversal. When we encounter a non-null node, ...

随机推荐

  1. C++编写一个简单的DLL

    什么是DLL: 自从微软推出16位的Windows操作系统起,此后每种版本的Windows操作系统都非常依赖于动态链接库(DLL)中的函数和数据,实际上 Windows操作系统中几乎所有的内容都由DL ...

  2. R语言笔记3--实例1

    综合性例子: 模拟产生统计专业同学的名单(学号区分),记录数学分析,线性代数.概率统计三科成绩,然后进行一些统计分析 1.首先产生一个向量(100个元素,代表100位学生) 2.模拟成绩 runif: ...

  3. FUSE

    FUSE is particularly useful for writing [ vritual ] file system. Unlike traditional filesystem that ...

  4. Mysql5.7 安装

    1 安装yum源 yum localinstall http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm2 参看源 vi ...

  5. postgres 数据库备份恢复

    postgre 数据库备份恢复命令 备份:pg_dump -U postgres -v -F c -Z 4 -f ***.backup dbname  9压缩率最狠恢复:pg_restore -U p ...

  6. psy

    本文的重点是讲解如何运用心理线指标看盘,运用周线月线的心理线来抓住大盘的顶部和底部的研究.分析研究的材料都来源于沪市历史上的顶部和底部的历史数据.从psy数据所得出的结论大多数是有效的,只有个别时期的 ...

  7. vs远程调试

    一.远程       建立共享目录debug 二.本地 1.生成->输出->输出路径,由"bin\Debug\"改为远程目录"\\xxx\\debug&quo ...

  8. ENC28j60以太网芯片驱动程序简介

    ENC28j60以太网芯片驱动程序简介 ENC28J60 驱动开发要点 enc28J60 和 Arduino (1)——ping通你的Arduino MCU51单片机uIP协议栈+ENC28J60网卡 ...

  9. ant 配置 和测试 1

    配置路径 D:\dba\change\UAT\unity\schema\test ----v0 版本 sql.xml   (默认target 是versionfinal ,也就是最终版本) --ver ...

  10. bash和sh区别

    在一般的linux系统当中(如redhat),使用sh调用执行脚本相当于打开了bash的POSIX标准模式(等效于bash的 --posix 参数),一般的,sh是bash的“子集”,不是子集的部分. ...