codeforces#292-C - Drazil and Factorial-数学规律题

http://codeforces.com/contest/515/problem/C

题意:给你一个n位的数字X,把他的每一位求阶乘累乘得到一个值F(X)

让你找一个最大的数a,满足:


1. x doesn't contain neither digit 0 nor digit 1.

2.  = .


如n=4;X=1234,则a=33222,因为

思路:

想到要求a最大,那么便尽可能使得长度越长自然就越大了....然后这里想歪了..想到让因子尽可能小,一开始傻逼到先用高精度把阶乘算一下然后再不断取除0~9

....

其实直接对数X里面的 每一位拆分即可,2 3 5 7 不变, 把 4 6 8 9拆分成更小的数

注意是阶层的关系。。。

4!拆成2个2!和1个3!

//6!拆成5的阶层和3!

//8!拆成7的阶层和3个2!

//9!拆成一个7!和一个2!和2个3!


拆完排序 输出时忽略0 1就可以了。。。


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include<stack>
using namespace std; 

int tm[100005];   
int main()
{ 
	int i,j;
	
	int n;
	scanf("%d",&n);
	
	int tmp=0;	int len=0;
	while(tmp==0)
	{
		scanf("%1d",&tmp);
		len++;
	}
	tm[1]=tmp;
	n=n-len+1;
	for (i=2;i<=n;i++)
	{
		scanf("%1d",&tm[i]); 
	} 
	len=n;
	
	for (j=1;j<=n;j++)
	{
		i=tm[j];
		if (i==2||i==3||i==5||i==7||i==1||i==0) continue; 
		if (i==4)
		{
			tm[j]=2;//4! 拆成2个2!和1个3!
			tm[++len]=2;
			tm[++len]=3; 
		}
		if(i==6)
		{
		 
			tm[j]=5; //6!拆成5的阶层和3!
			tm[++len]=3; 
			//........6		
			
		}
		if (i==8)
		{ 
			tm[j]=7;//8!拆成7的阶层和3个2!
			tm[++len]=2;

		 	tm[++len]=2;//......4
			tm[++len]=2; 

		}
		if (i==9)
		{ 

			tm[j]=7;//9!拆成一个7!和一个2!和2个3!
			tm[++len]=2; 
		  
			//************8
			tm[++len]=3;
			tm[++len]=3;

		}
	} 
	
	sort(tm+1,tm+1+len); 
	for (i=len;i>=1;i--)
	{
		if (tm[i]==1||tm[i]==0) continue;
			printf("%d",tm[i]);
	}
	printf("\n");
	return 0;
	
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值