Codeforces 658A. 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
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).
题目链接:http://codeforces.com/problemset/problem/685/A
题意:一天有n个小时,每小时有m分钟。一个7进制表示的时钟一天内有几次钟表上出现的数字均不相同。
代码:
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int getnum(int x)
{
int gg=;
if(x==)
return ;
while(x)
{
x/=;
gg++;
}
return gg;
}
int sign[];
int num[];
map< int, map<int,int> >gg;
int DFS(int x,int len)
{
int i,j;
if(x==len)
{
/*
for(i=1;i<=len;i++)
cout<<num[i]<<" ";
cout<<endl;
*/
for(i=; i<len; i++)
{
int hh=,mm=;
int base=;
for(j=i; j>=; j--)
{
hh+=num[j]*base;
base*=;
}
base=;
for(j=len; j>i; j--)
{
mm+=num[j]*base;
base*=;
}
//cout<<"hh="<<hh<<" mm="<<mm<<endl;
if(hh<=n&&mm<=m)
{
if(gg[hh][mm]==) ans++;
gg[hh][mm]=;
}
if(hh>n) break;
}
}
for(i=; i<; i++)
{
if(sign[i]==)
{
num[x+]=i;
sign[i]=;
DFS(x+,len);
sign[i]=;
}
}
}
int main()
{
int i;
scanf("%d%d",&n,&m);
n--;
m--;
int len=getnum(n)+getnum(m);
if(len>) cout<<""<<endl;
else
{
memset(sign,,sizeof(sign));
memset(num,,sizeof(num));
ans=;
DFS(,len);
cout<<ans<<endl;
}
return ;
}
Codeforces 658A. Robbers' watch 模拟的更多相关文章
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
- Codeforces 438D (今日gg模拟第二题) | 线段树 考察时间复杂度的计算 -_-|||
Codeforces 438D The Child and Sequence 给出一个序列,进行如下三种操作: 区间求和 区间每个数模x 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...
- CodeForces 2A - Winner(模拟)
题目链接:http://codeforces.com/problemset/problem/2/A A. Winner time limit per test 1 second memory limi ...
随机推荐
- mysql数据表自动导为python sqlalchemy可操作对象
1.pip install sqlacodegen pip install pymysql 在/usr/lib/python/site-packages/sqlacodegen/main.py中添 ...
- selenium+python自动化84-chrome手机wap模式(登录淘宝页面)
前言 chrome手机wap模式登录淘宝页面,点击验证码无效问题解决. 切换到wap模式,使用TouchActions模块用tap方法触摸 我的环境 chrome 62 chromedriver 2. ...
- 13.mysql基本查询
1. 给表起个别名:但是,前面的也是需要进行修改的,否则会报错的: select * from s.name from students as s; 2. 为字段起别名 select s,name a ...
- Node fs, url, http 组合小型的服务器 ( 满足html请求, get, post 传值 )
<script type="text/javascript"> /* * 引入模块 */ var http = require('http'); var url = r ...
- 关联github, 添加gitignore 规则
1. 新建Maven项目 2. 新建github repository 3. 执行命令 echo "# se" >> README.md git init git ad ...
- mavenLocal默认地址转移
maven的默认本地仓库为 USER_HOME/.m2/ windows开发我们大多不会讲本地仓库放在c盘下,而是重新指定了另一个存储位置. 在gradle中 使用 mavenLocal() 时的查找 ...
- 5 并发编程-(进程)-队列&生产者消费者模型
1.队列的介绍 进程彼此之间互相隔离,要实现进程间通信(IPC),multiprocessing模块支持两种形式:队列和管道,这两种方式都是使用消息传递的 创建队列的类(底层就是以管道和锁定的方式实现 ...
- 4 并发编程-(进程)-守护进程&互斥锁
一.守护进程 主进程创建子进程,然后将该进程设置成守护自己的进程,守护进程就好比崇祯皇帝身边的老太监,崇祯皇帝已死老太监就跟着殉葬了. 关于守护进程需要强调两点: 其一:守护进程会在主进程代码执行结束 ...
- Rsync+sersync实现数据实时同步
前言: 一.为什么要用Rsync+sersync架构? 1.sersync是基于Inotify开发的,类似于Inotify-tools的工具 2.sersync可以记录下被监听目录中发生变化的(包括增 ...
- 启用SQL Server 2008的专用管理员连接(DAC)
参考:http://technet.microsoft.com/zh-cn/library/ms178068(v=SQL.105).aspx 问题: 一个在我们公司实习的DBA向我询问如何开启SQL ...