Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力
A. Robbers' watch
题目连接:
http://www.codeforces.com/contest/685/problem/A
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
Sample Output
4
Hint
题意
有n个小时,m分钟,7进制时间,问你这一天一共有多少个时间,他的数字都不相同。
题解:
差点就写数位dp了……
首先,如果这个时钟的数字超过了7位,那么肯定有相同的,根据鸽巢原理很容易判断出来
然后小于七位的,实际上数字就很少了,我们直接暴力就好了……
然后这道题就完了。
代码
#include<bits/stdc++.h>
using namespace std;
int num[10],ans;
void check(int x,int y,int n,int m)
{
for(int i=0;i<10;i++)num[i]=0;
if(!n)num[0]++;
if(!m)num[0]++;
while(n){
num[x%7]++;
x/=7;
n/=7;
}
while(m){
num[y%7]++;
y/=7;
m/=7;
}
for(int i=0;i<10;i++)
if(num[i]>1)return;
ans++;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
if(1ll*n*m>1e7){
puts("0");
return 0;
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
check(i,j,n-1,m-1);
cout<<ans<<endl;
}
Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力的更多相关文章
- 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
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 Round #359 (Div. 1)
A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...
- Codeforces Round #359 (Div. 1) B. Kay and Snowflake dfs
B. Kay and Snowflake 题目连接: http://www.codeforces.com/contest/685/problem/B Description After the pie ...
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题
B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #359 (Div. 2) C
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- windows环境cmd下执行jar
项目目录结构 一,在pom.xml文件里添加配置 <build> <plugins> <plugin> <groupId>org.apache.mave ...
- swagger学习
https://segmentfault.com/a/1190000010144742 https://segmentfault.com/a/1190000014775124 https://blog ...
- c# List 所有操作方法例子
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Ref ...
- VirtualBox上安装CentOS-7(Minimal)
Windows 10家庭中文版,VirtualBox 5.2.12,CentOS 7(Minimal版), 因为听到大家在谈论CentOS,阿里云上也有CentOS,CentOS还是Red Hat出品 ...
- maven pom.xml配置
<repositories> <repository> <id>central</id> <name>Maven Repository Sw ...
- JavaScript 中的回调函数
原文:http://javascriptissexy.com/ 翻译:http://blog.csdn.net/luoweifu/article/details/41466537 [建议阅读原文,以下 ...
- MySQL学习笔记:case when
一.MySQL case when的三种用法: 1.case 字段 when, 字段的具体值: select a.*, case sex when '1' then '男' else '女' end ...
- CVE-2012-0158基于exp分析
CVE-2012-0158这个洞我之前分析过,漏洞战争这本书里也写过,但是都是用poc分析的,我这次找了一个弹计算器的exp来分析,感觉用poc和用exp还是不一样的,从exp分析要比从poc分析更复 ...
- 提高eclipse使用效率(二)—— 提高Android开发效率的小技巧
XML文件的代码提示 adt中也有xml文件的代码提示,为了让提示来的更加猛烈,我们还要设置一下 打开eclipse - Window - Preferences,在右边的目录树中切换到XML - X ...
- SPOJ - SUBLEX 后缀自动机
SPOJ - SUBLEX 思路:求第k大字串,求出sam上每个节点开始能识别多少字串,然后从起点开始跑就好啦. #include<bits/stdc++.h> #define LL lo ...