Codeforces Round #359 (Div. 2) C. Robbers' watch 鸽巢+stl
2016-06-24 10:42
381 查看
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
output
input
output
Note
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位数,即判断位数的时候要小心
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
Note
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+10,M=1e6+10,inf=1e9+10; int getnum(int x) { int ans=0; if(x==0) return 1; while(x) { x/=7; ans++; } return ans; } int a[10]={0,1,2,3,4,5,6}; pair<int,int>p; map<pair<int,int>,int>m; int check(int pos,int len,int x,int y) { int base=1; int num=0; for(int i=pos-1;i>=0;i--) { num+=a[i]*base; base*=7; } int shu=0; base=1; for(int i=len-1;i>=pos;i--) { shu+=a[i]*base; base*=7; } if(num<=x&&shu<=y) { if(m[make_pair(num,shu)]) return 0; else { m[make_pair(num,shu)]=1; return 1; } } return 0; } int main() { int x,y,z,i,t; scanf("%d%d",&x,&y); x--; y--; z=getnum(x)+getnum(y); if(z>7) printf("0\n"); else { int ans=0; do { for(i=1;i<z;i++) if(check(i,z,x,y)) { ans++; } }while(next_permutation(a,a+7)); printf("%d\n",ans); } return 0; }
相关文章推荐
- 软件工程学期总结
- 2025查找最大元素
- sqlserver2008恢复误删记录的一种方法
- Android 如何让dialog不消失,即使是用户按了返回键dialog也不消
- IQKeyboardManager基本使用
- zabbix2.4的安装
- String类型的属性和方法
- Android 5.1 - 状态栏充电标志问题
- 【操作系统】处理机调度与死锁(三)
- asp.net mvc Html.BeginForm()用法
- 一个简单安全的PHP验证码类 附调用方法
- Ubuntu 12.04安装和设置SSH服务
- iOS 清理缓存简介
- python爬虫-京东登录
- android的充电图标显示
- react 组件的生命周期
- C++编程笔记:struct和typedef struct的区别
- 常见的 libphp5.so文件无法生成的问题
- Cobbler6.4 linux系统自动化安装脚本
- Apace、Ngnix、Tomcat三者关系