每日一题 第七十三期 洛谷 [蓝桥杯 2013 省 B] 带分数

[蓝桥杯 2013 省 B] 带分数

题目描述

100 100 100 可以表示为带分数的形式: 100 = 3 + 69258 714 100 = 3 + \frac{69258}{714} 100=3+71469258。

还可以表示为: 100 = 82 + 3546 197 100 = 82 + \frac{3546}{197} 100=82+1973546。

注意特征:带分数中,数字 1 1 1 ~ 9 9 9 分别出现且只出现一次(不包含 0 0 0)。

类似这样的带分数, 100 100 100 有 11 11 11 种表示法。

输入格式

从标准输入读入一个正整数 N ( N < 1 0 6 ) N(N<10^6) N(N<106)。

输出格式

程序输出数字 N N N 用数码 1 1 1 ~ 9 9 9 不重复不遗漏地组成带分数表示的全部种数。

注意:不要求输出每个表示,只统计有多少表示法!

样例 #1

样例输入 #1

复制代码
100

样例输出 #1

复制代码
11

样例 #2

样例输入 #2

复制代码
105

样例输出 #2

复制代码
6

提示

原题时限 3 秒, 64M。蓝桥杯 2013 年第四届省赛

AC代码:

cpp 复制代码
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<iomanip>
#define endl '\n'
//#define x first
//#define y second
using namespace std;

typedef long long ll;
typedef pair<int, int>PII;
//const int N=3e5+10;
const int MOD=1e9 + 7;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;

int target;
int num[50];
bool use[50];
int cnt;
int cal(int l , int r)
{
	int res = 0;
	for(int i = l; i <= r; i ++)
	{
		res = res * 10 + num[i];
	}
	return res;
}
void dfs(int u)
{
	if(u == 9)
	{
		for(int i = 0; i < 7; i ++)
		{
			for(int j = i + 1; j < 8; j ++)
			{
				int a = cal(0, i);
				int b = cal(i + 1, j);
				int c = cal(j + 1, 8);
				if(a * c + b == c * target)cnt ++;
			}
		}
		return ;
	}
	for(int i = 1; i <= 9; i ++)
	{
		if(!use[i])
		{
			use[i] = true;
			num[u] = i;
			dfs(u + 1);
			use[i] = false;
		}
	}
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	cin >> target;
	dfs(0);
	cout << cnt << endl;
}
相关推荐
爱研究的小陈2 分钟前
Day 3:数学基础回顾——线性代数与概率论在AI中的核心作用
算法
渭雨轻尘_学习计算机ing5 分钟前
二叉树的最大宽度计算
算法·面试
再睡一夏就好11 分钟前
Linux常见工具如yum、vim、gcc、gdb的基本使用,以及编译过程和动静态链接的区别
linux·服务器·c语言·c++·笔记
BB_CC_DD38 分钟前
四. 以Annoy算法建树的方式聚类清洗图像数据集,一次建树,无限次聚类搜索,提升聚类搜索效率。(附完整代码)
深度学习·算法·聚类
YHY_13s42 分钟前
访问者模式
c++·访问者模式
我也不曾来过11 小时前
list底层原理
数据结构·c++·list
A charmer1 小时前
C++ 日志系统实战第三步:熟悉掌握各种设计模式
c++·日志系统
Ethon_王1 小时前
STL容器适配器详解:queue篇
c++
静听夜半雨1 小时前
CANoe入门——3、新建LIN工程及LIN DataBase(LDF文件)的创建
网络·数据库·c++·编辑器
梁下轻语的秋缘2 小时前
每日c/c++题 备战蓝桥杯 ([洛谷 P1226] 快速幂求模题解)
c++·算法·蓝桥杯