Codeforces Round #359 (Div. 2) C. Robbers' watch 鸽巢+stl
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
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的分钟用七进制表示,所有数字都不相同的个数,不足的位置用0补;
思路:根据鸽巢,首先最多7个数不同,用全排列next_mutation解决,一个小坑就是7为1位数,即判断位数的时候要小心
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
int getnum(int x)
{
int ans=;
if(x==)
return ;
while(x)
{
x/=;
ans++;
}
return ans;
}
int a[]={,,,,,,};
pair<int,int>p;
map<pair<int,int>,int>m;
int check(int pos,int len,int x,int y)
{
int base=;
int num=;
for(int i=pos-;i>=;i--)
{
num+=a[i]*base;
base*=;
}
int shu=;
base=;
for(int i=len-;i>=pos;i--)
{
shu+=a[i]*base;
base*=;
}
if(num<=x&&shu<=y)
{
if(m[make_pair(num,shu)])
return ;
else
{
m[make_pair(num,shu)]=;
return ;
}
}
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d%d",&x,&y);
x--;
y--;
z=getnum(x)+getnum(y);
if(z>)
printf("0\n");
else
{
int ans=;
do
{
for(i=;i<z;i++)
if(check(i,z,x,y))
{
ans++;
}
}while(next_permutation(a,a+));
printf("%d\n",ans);
}
return ;
}
Codeforces Round #359 (Div. 2) C. Robbers' watch 鸽巢+stl的更多相关文章
- 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
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 (暴力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. 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 ...
随机推荐
- 【JVM】程序调优
现实企业级Java开发中,有时候我们会碰到下面这些问题: OutOfMemoryError,内存不足 内存泄露 线程死锁 锁争用(Lock Contention) Java进程消耗CPU过高 .... ...
- 如何删除Docker中的镜像相关
1.正常情况下 1.停止所有的container,这样才能够删除其中的images: docker stop $(docker ps -a -q) 如果想要删除所有container的话再加一个指令: ...
- git学习------> Gitlab如何进行备份恢复与迁移?
前段时间,在某台CenterOS服务器上搭建了Gitlab环境,并且大家陆陆续续的都把代码从svn迁移到了gitlab,但是之前的CenterOS服务器并不是搭建在公司的机房环境,而是搭建在办公室的某 ...
- java实现简单的数据库的增删查改,并布局交互界面
一.系统简介 1.1.简介 本系统提供了学生信息管理中常见的基本功能,主要包括管理员.管理员的主要功能有对学生信息进行增加.删除.修改.查找等操作,对信息进行管理,对信息进行修改.查找等操作 ...
- Java集合—Queue(转载)
Queue用于模拟队列这种数据结构,队列通常是指“先进先出”(FIFO)的容器.新元素插入(offer)到队列的尾部,访问元素(poll)操作会返回队列头部的元素.通常,队列不允许随机访问队列中的元素 ...
- Jmeter(十)Linux下配置安装Jmeter及执行测试任务
一.安装JDK7.0版本 1.先卸载服务器自带的jdk软件包 # java -version #查看服务器是否安装过 # rpm -qa |grep gcj #查看服务器安装的jdk软件包信息 # y ...
- 创建正真的Java不可变类
如果需要设计一个不可变类,尤其要注意其引用类型Field,如果其引用类型Field的类是可变的,就必须采取必要的措施来保护该Field所引用的对象不会被修改,这样才能创建真正的不可变类. class ...
- 打开的文件符合PDF/A标准,且已在只读模式下打开,以防被修改
PDF/A是一种用于长期归档和保留电子文档的ISO标准.您扫描到PDF的文档符合PDF/A的规范.您可以指定是否要用本查看模式查看文档. PDF/A 问题提示:“打开的文件符合PDF/A标准,且已在只 ...
- appium 底层原理
appium的log详细分析http://blog.csdn.net/jffhy2017/article/details/69372064----------------------很多appium架 ...
- CSS实现文本超过指定长度显示省略号
<style type="text/css"> li { width:200px;/*宽度,超过即会溢出*/ line-height:25px;/*设置行间距*/ te ...