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 ...
随机推荐
- UVA-839-二叉树-一个有意思的题目
题意: 一颗二叉树可以看成一个杠杆,左右俩边有重量,有到支点长度,判断整个树是否平衡(根据杠杆原理),如果当前结点有左孩子,那么当前左边的重量就是左孩子的总和,右边同理 递归,发现scanf和cin的 ...
- UVA327
模拟 这个问题的任务是求解一组c语言里的表达式,但是你不需要知道c语言是怎么解决这个问题!每一行一个表达式,每个表达式的组成不会超过110个字符.待求解的表达式只包含一个int类型变量和一个组有限的操 ...
- JAVA时间进行比较和转换,时间加减得到天数
转自:https://blog.csdn.net/iteye_8535/article/details/82246006 JAVA时间进行比较和转换,时间加减得到天数 1. 把时间类型的字符串转为DA ...
- as3 根据鼠标移动方向
gz 为一个影片 import flash.display.Sprite; stage.addEventListener(MouseEvent.MOUSE_MOVE, onStageMouseMove ...
- c++ static成员
static 成员通常不能在类的定义体重初始化 有一种例外,const static成员可以在定义体内初始化,并且可以用于构造函数 将函数声明为const表示该函数不能修改其所属的对象
- Mysql 知识(1)
1. 请简洁地描述下MySQL中InnoDB支持的四种事务隔离级别名称,以及逐级之间的区别? 答: SQL标准定义的四个隔离级别为:read uncommited,read committed,rep ...
- How to Pronounce OPPORTUNITY
How to Pronounce OPPORTUNITY Share Tweet Share Take the opportunity to learn this word! Learn how t ...
- testlink问题--linux环境下
搭建testlink 时出现问题,相关解决办法: 1.Maximum Session Idle Time before Timeout 修改php.ini文件,修改成session.gc_maxlif ...
- cubic与spline插值点处的区别
cubic与spline都是Matlab的三次样条插值法,但是它们在插值点处仍然有着很微妙的区别,这个区别说明不了两种方法的好坏,只能根据实际情况进行合理筛选.以一维插值为例: clc clear % ...
- nyoj528-找球号(三) 【位运算】
http://acm.nyist.net/JudgeOnline/problem.php?pid=528 找球号(三) 时间限制:2000 ms | 内存限制:3000 KB 难度:2 描述 ...