Binary Watch
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
- 样例输出
-
00:01
00:02
00:04
00:08
00:16
00:32
01:00
02:00
04:00
08:00
16:00
分析:数据范围很小,暴力即可;
代码:#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define pii pair<int,int>
#define fi first
#define se second
const int maxn=3e4+;
using namespace std;
int n,m;
int work(int a,int b)
{
int cnt=;
while(a)
{
if(a&)cnt++;
a>>=;
}
while(b)
{
if(b&)cnt++;
b>>=;
}
return cnt;
}
int main()
{
int i,j,k,t;
scanf("%d",&n);
rep(i,,)rep(j,,)
{
if(work(i,j)==n)printf("%02d:%02d\n",i,j);
}
//system("pause");
return ;
}
Binary Watch的更多相关文章
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
- Leetcode: Convert sorted list to binary search tree (No. 109)
Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...
- 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 ...
- [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 ...
- [LeetCode] Find Leaves of Binary Tree 找二叉树的叶节点
Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps un ...
- [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, ...
随机推荐
- 4-static(静态变量)关键字
1.使用static声明属性 static声明全局属性2.使用static声明方法 直接通过类名调用3.注意点 使用static方法的时候,只能访问static声明的属性和方法,而非static声明的 ...
- 菜鸟认识揭开DLL木马
相信经常玩木马的朋友们都会知道一些木马的特性,也会有自己最喜爱的木马,不过,很多朋友依然不知道近年兴起的“DLL木马”为何物.什么是“DLL木马”呢?它与一般的木马有什么不同? 一.从DLL技术说起 ...
- 《JS权威指南学习总结--4.9.3in和instanceof运算符》
内容要点: 一.in运算符 in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望它的右操作数是一个对象.如果右侧的对象拥有一个名为左操作数数值的属性名,那么表达式返回true. 例如: va ...
- 新随笔ps泡泡制作
http://jingyan.baidu.com/article/4d58d5413568a79dd4e9c016.html
- java web 项目如何部署到互联网中 通过输入域名访问?
https://segmentfault.com/q/1010000000710271
- jquery新窗口打开链接
第一种:下面的代码是针对m35ui这个样式下的a都是在新窗口打开 <script type="text/javascript"> jQuery(document ...
- iOS中的多线程基础
NSThread NSThread是一个苹果封装过的,面向对象的线程对象.但是它的生命周期需要我们自己来手动管理,所以使用不是很常见,比如[NSThread currentThread],它可以获取当 ...
- 在PL/SQL/sqlplus客户端 中如何让程序暂停几秒钟
1. how to check procedure exist: SQL> conn oper/oper123Connected.SQL> desc dbms_lock;PROCEDURE ...
- C# API 大全
C:\ProgramFiles\MicrosoftVisual Studio .NET\ FrameworkSDK\Samples\ Technologies\ Interop\PlatformInv ...
- 将页面内容转为Excel下载
使用:method1(table); 说明:参数table为table元素的ID; var idTmr; function getExplorer() { var explorer = window. ...