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 ...
随机推荐
- imperva-指定url禁止访问
指定url禁止访问 应用到那个网站 访问一下查看告警
- 电脑蓝屏提示unexpected store exception的解决方法
在我们使用电脑的过程中常常会遇到许多问题,对于许多不熟悉电脑的用户常常摸不着头脑,而部分用户在使用电脑时,电脑常常出现蓝屏的情况,并提示你的电脑遇到问题需要重新启动,与此同时,其报告错误代码为“une ...
- avalonJS-源码阅读(三) VMODEL
avalon的重头戏.终于要到我最期待的vmodel了. ps:这篇博文想做的全一点,错误少一点,所以会有后续的更新在这篇文章中. 状态:一稿 目录[-] avalon dom小结 数据结构 观察者模 ...
- java 一个函数如何返回多个值
在开发过程中,经常会有这种情况,就是一个函数需要返回多个值,这是一个问题!! 网上这个问题的解决方法: 1.使用map返回值:这个方法问题是,你并不知道如何返回值的key是什么,只能通过doc或者通过 ...
- 微软Holographic将更名为Windows Mixed Reality
微软Holographic将更名为Windows Mixed Reality ----世界变化好快. 还没来得及细细品味,它就已经更名了. 程序员的焦虑,处在一个信息大爆炸的年代,大数据,云计算,机 ...
- SpringCloud常用注解
一 @EnableDiscoveryClient,@EnableEurekaClient的区别 SpringCLoud中的“Discovery Service”有多种实现,比如:eureka, con ...
- Java--Jackson转换Date,Timestamp 到格式化字符串
package com.diandaxia.test; import java.sql.Timestamp; import java.util.Date; /** * Created by del-b ...
- Centos之文件搜索命令locate
locate命令 locate 文件名 在后台数据库中按文件名搜索,搜索速度更快 /var/lib/mlocate #locate命令所搜索的后台数据库 updatedb 更新数据库 locate搜索 ...
- LeetCode691. Stickers to Spell Word
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...
- 安装SHARP MX-3618NC PCL6打印机驱动程序
第一步, 打开MX-CR3_PCL_PS_1302a_ChineseS_Win8Server2012.exe 驱动程序 此驱动支持Win8.Server2012及以下版本的操作系统,同时兼容Win1 ...