C. Robbers' watch
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
2 3
output
4
input
8 2
output
5

链接:http://codeforces.com/contest/686/problem/C晚上做的时候想到了位数大于7的时候,输出0,但就是没想到之后暴力就可以解了 = =
还有,这代码中的判断条件想法也比较好,开一个used的vector,之后判断每个数变成7进制之后的各个数出现的次数,如果其中最大的小于等于1,那么就可行。这种想法真的很好,写着也简洁,需要学习。
#include <bits/stdc++.h>
using namespace std; int main()
{
//这是加速cin的,网上说用完之后,速度和scanf差不多
iostream::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr); //size_t 相当于无符号int
size_t n,m;
cin>>n>>m;
size_t len1=,len2=;
for (size_t a=;a<n;a*=)
len1++;
for (size_t b=;b<m;b*=)
len2++; size_t ans=;
if (len1+len2<=)
for (size_t i=;i<n;i++)
for (size_t j=;j<m;j++)
{
vector<size_t> used(,);
for (size_t a=i,k=;k<len1;a/=,k++)
{
used[a%]+=;
}
for (size_t b=j,k=;k<len2;k++,b/=)
{
used[b%]+=;
} //max_element 返回迭代器,所以要解引用
if (*max_element(used.begin(),used.end())<=)
ans++;
}
cout<<ans<<endl; return ;
}

Codeforces Round #359 (Div. 2)C - Robbers' watch的更多相关文章

  1. Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力

    A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...

  2. 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 ...

  3. Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索

    题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...

  4. 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 ...

  5. Codeforces Round #359 (Div. 1)

    A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #359 (Div. 2) C

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. spark新能优化之数据本地化

    数据本地化的背景: 数据本地化对于Spark Job性能有着巨大的影响.如果数据以及要计算它的代码是在一起的,那么性能当然会非常高.但是,如果数据和计算它的代码是分开的,那么其中之一必须到另外一方的机 ...

  2. HDU-4521 小明系列问题――小明序列(线段树)

    题目大意:求LIS,但是要求LIS中相邻的两个元素之间的距离要大于d. 题目分析:线段树.节点(l,r)保存信息为LIS的最后一个元素落在[l,r]之间的最大长度.从第d+2个元素开始查询更新操作,但 ...

  3. Git连接Github

    环境:Ubuntu Server 12.04 安装Git apt-get install git git-core 配置本机Git git config --global user.name &quo ...

  4. 服务器启用 FTP

    通常使用 vsftpd 作为FTP服务器. 安装 vsftpd: 1.以管理员(root)身份执行以下命令 yum install vsftpd 2.设置开机启动 vsftpd ftp 服务 chkc ...

  5. URL 正则表达式

    (http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])? From h ...

  6. CUDA Thread Indexing

    1D grid of 1D blocks __device__ int getGlobalIdx_1D_1D() { return blockIdx.x *blockDim.x + threadIdx ...

  7. Navicat导入数据时发生了报错 --- 1153 - Got a packet bigger than 'max_allowed的处理办法

    今天我在使用Navicat导入.sql文件数据时,发现本来是80万条的数据,结果只导入了10万条左右,而且在其错误信息日志中,我发现了这样一条错误:1153 - Got a packet bigger ...

  8. share point 读取 metadata

    private static void syncMetaData() { var siteUrl = @"http://..."; using (var site = new SP ...

  9. Web前端开发笔试&面试_03

    WL: 1.如何显示.隐藏一个dom对象? 2.如何将一个网页中的内容水平置中?写出重要的html标签和css. (css:#content{align:center;float:left;}html ...

  10. Open vSwitch

    https://github.com/openvswitch/ovs/blob/master/INSTALL.RHEL.md