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 ...
随机推荐
- 编写函数digit(num, k),函数功能是:求整数num从右边开始的第k位数字的值,如果num位数不足k位则返回0。
function digit(num,k){ var knum = 0; for(var i=1; i<=k; i++){ knu ...
- Java反射 - 简单的给Bean赋值和取值
由于项目的实际需要,所以利用java反射原理写了一个简单给bean赋值和取值通用的类,在此记录下方便自己日后用到,也为需要的兄弟提供个参考例子. 工具类BeanRefUtil: package c ...
- concurrent.futures模块
1.concurrent.futures模块介绍 2.ThreadPoolExecutor线程池使用 3.ProcessPoolExecutor进程池使用 4.其他方法使用 1.concurrent. ...
- CYQ.Data 轻量数据层之路 使用篇二曲 MAction 数据查询(十三)----002
原文链接:https://blog.csdn.net/cyq1162/article/details/53303390 前言说明: 本篇继续上一篇内容,本节介绍所有相关查询的使用. 主要内容提要: 1 ...
- spring boot + jpa + kotlin入门实例
spring boot +jpa的文章网络上已经有不少,这里主要补充一下用kotlin来做. kotlin里面的data class来创建entity可以帮助我们减少不少的代码,比如现在这个User的 ...
- c++官方文档-class
#include <iostream> using namespace std; class Circle { double radius; public: Circle(double r ...
- zabbix_get无法执行agent端的脚本文件解决办法
一,无法执行脚本参考网站:http://blog.51cto.com/13589448/2070180 权限不足时提示: server端提示: [root@yao local]# zabbix_get ...
- leetcode166
public class Solution { public String fractionToDecimal(int numerator, int denominator) { HashMap< ...
- UI5-文档-4.30-Debugging Tools
虽然我们在前面的步骤中添加了一个基本的测试覆盖率,但是我们似乎不小心破坏了我们的应用程序,因为它不再显示价格到我们的发票上.我们需要调试这个问题,并在有人发现之前修复它. 幸运的是,SAPUI5提供了 ...
- HTTP状态码 解析
原文地址:HTTP状态码:400500错误代码(个人总结)作者:lining2008net 一些常见的状态码为: 200-服务器成功返回网页 404-请求的网页不存在 503-服务不可用 详细分解: ...