codeforces 359 C - Robbers' watch
Description
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 ≤ n, m ≤ 109) — the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Sample Input
2 3
4
8 2
5
Hint
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
题意:给你时钟的n和m,7进制数,判断有多少种显示的方式使得时钟上每一个数字都不重复。
思路:由于只有7个数,所以n和m转化为7进制以后,如果位数多余7则一定没有解,所以只有当两个数的位数之和小于等于7的时候才有解,我们会发现此时的数是比较小的,所以我们可以直接暴力计算结果。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool vis[];
bool judge(int x ,int len)
{
int sum=;
while(x)
{
if(vis[x%])
{
return ;
}
vis[x%]=;
x/=;
sum++;
}
for(int i=sum; i<len; i++)
{
if(vis[]==) return ;
vis[]=;
}
return ;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
int ans=;
int len1=;
int len2=;
for(int i=; i<n; i*=) len1++;
for(int i=; i<m; i*=) len2++;
if(len1+len2<=)
{
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
memset(vis,,sizeof(vis));
if(i==j||(!judge(i,len1))||(!judge(j,len2))) continue; //判断是否重复
ans++;
}
}
}
cout<<ans<<endl;
return ;
}
codeforces 359 C - Robbers' watch的更多相关文章
- 套题 codeforces 359
A题:Free Ice Cream 注意要使用LL,避免爆int #include <bits/stdc++.h> #define scan(x,y) scanf("%d%d&q ...
- codeforces 686C C. Robbers' watch(dfs)
题目链接: C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #359 (Div. 2)C - Robbers' watch
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力
A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)
题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索
题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch 鸽巢+stl
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces 658A. Robbers' watch 模拟
A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces Round #359 (Div. 1)
A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...
随机推荐
- web 网站安全证书已过期或不可信 是否继续浏览
发生环境:魅族MX4 uc浏览器 IIS部署SSL证书后提示不可信的解决方案 第一步:打开mmc——点击文件——添加删除管理单元——证书——计算机帐户 第二步:在计算机帐户的个人证书里面导入pfx格 ...
- NIO组件Selector详解
Selector(选择器)是Java NIO中能够检测一到多个NIO通道,并能够知晓通道是否为诸如读写事件做好准备的组件.这样,一个单独的线程可以管理多个channel,从而管理多个网络连接. 下面是 ...
- spring boot项目配置文件集合
表 1. Spring Boot 推荐的基础 POM 文件 名称 说明 spring-boot-starter 核心 POM,包含自动配置支持.日志库和对 YAML 配置文件的支持. spring-b ...
- PAT---1050. String Subtraction (20)
#include<iostream> #include<string.h> #include<stdio.h> using namespace std; #defi ...
- dig命令 安装
获取容器 dns 信息 需要安装dig 命令 yum install bind-utils
- Java 加密 base64 encode
版权声明:本文为博主原创文章,未经博主允许不得转载. [前言] 计算机中的数据都是二进制的,不管是字符串还是文件,而加密后的也是二进制的, 而我们要看到的往往是字符串,本文就介绍了将byte[]转为各 ...
- TCP keepalive
2. TCP keepalive overview In order to understand what TCP keepalive (which we will just call keepa ...
- asp.net中ScriptManager自带Ajax与jQuery事件冲突
问题引诉:最近在使用asp.net自带的无刷新提交ScriptManager时,发现一个问题,就是和我自己用jQuery写的一些事件函数和局部刷新相冲突.通过在网上收索,发现很多人都遇到这个同样的问题 ...
- 异步DNS解析的实现
在高性能爬虫为什么使用定制DNS客户端一文中阐述了DNS解析是网络爬虫的瓶颈. 目前主要有两种方法来提高DNS解析效率: 1. 基于多线程的DNS 解析 2. 基于NIO的DNS解析 dnsjava中 ...
- servlet HttpSession 监听器
一.Servlet中对象作用域 1. ServletContext 上下文 应用服务器一启动就产生该对象,服务器关闭即销毁 作用于全局,所有Servlet ,相当于静态变量 2. HttpSessio ...