Codeforces Round #359 (Div. 2)C - Robbers' watch
2 seconds
256 megabytes
standard input
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.
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.
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.
2 3
4
8 2
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的更多相关文章
- 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 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 ...
随机推荐
- 【SDOI2008】【P1377】仪仗队
欧拉函数的应用 原题: 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是 ...
- 论文笔记之:MatchNet: Unifying Feature and Metric Learning for Patch-Based Matching
MatchNet: Unifying Feature and Metric Learning for Patch-Based Matching CVPR 2015 本来都写到一半了,突然笔记本死机了 ...
- 使用substring和split方法从字符串中抽取一组清单
提取前: '这是一个句子.这是一个句子,包含了一列清单: 樱桃, 橙子, 桔子, 苹果, 香蕉.这是清单内容.'; 提取后: ["樱桃", " 橙子", &qu ...
- VS 2012 C#快捷键
ctrl + J 重现智能提示 ctrl + L 删除一行ctrl + K ctrl + C 注释选中行ctrl +K ctrl +U 取消注释 ctrl +K ctrl +F 格式 ...
- java_queue
队列是一种特殊的线性表,先进先出(first in first out)FIFO,它只允许在表的前端(front)进行删除操作,只允许在表的后端(rear)进行插入操作. 实际应用:排队等待公交车,银 ...
- PgSQL · 追根究底 · WAL日志空间的意外增长
问题出现 我们在线上巡检中发现,一个实例的pg_xlog目录,增长到4G,很是疑惑.刚开始怀疑是日志归档过慢,日志堆积在pg_xlog目录下面,未被清除导致.于是检查归档目录下的文件,内容如下.但发现 ...
- sublime安装sftp和ctags插件
1. 安装Package Control插件 , 安装是通过Sublime Text 2控制台.这是通过按Ctrl + `快捷访问.一旦打开,粘贴以下命令到控制台. 输入以下python代码 subl ...
- 【转】[NOIP2003普及组]麦森数
来源:http://vivid.name/tech/mason.html 不得不纪念一下这道题,因为我今天一整天的时间都花到这道题上了.因为这道题,我学会了快速幂,学会了高精度乘高精度,学会了静态查错 ...
- 目录处理工具类 DealWithDir.java
package com.util; import java.io.File; /** * 目录处理工具类 * */ public class DealWithDir { /** * 新建目录 */ p ...
- 【mybaits】Mybatis中模糊查询的各种写法
工作中用到,写三种用法吧,第四种为大小写匹配查询 1. sql中字符串拼接 SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{t ...