Codeforces Round #292 Div1 A

Problem

Drazil is playing a math game with Varda.

Let’s define for positive integer x as a product of factorials of its digits. For example, .

First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:

1. x doesn’t contain neither digit 0 nor digit 1.
2. F(x)=F(a) .

Help friends find such number.

Limits

TimeLimit(ms):2000

MemoryLimit(MB):256

n∈[1,15](the number of digits in a)

There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.

Look up Original Problem From here

Solution

考虑数a的每个digit,0和1忽略,其余若是素数则无法拆分,即2!=2!,3!=3!,5!=5!,7!=7!;

非素数可以拆分:

4!=4×3!=2!×2!×3!

6!=6×5!=3!×5!

8!=2!×2!×2!×7!

9!=2!×3!×3!×7!

按此维护答案即可

Complexity

TimeComplexity:O(n)

MemoryComplexity:O(n)

My Code

//Hello. I‘m Peter.
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uin;
#define peter cout<<"i am peter"<<endl
#define input freopen("data.txt","r",stdin)
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define gsize(a) (int)a.size()
#define len(a) (int)strlen(a)
#define slen(s) (int)s.length()
#define pb(a) push_back(a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_minus1(a) memset(a,-1,sizeof(a))
#define clr_INT(a) memset(a,INT,sizeof(a))
#define clr_true(a) memset(a,true,sizeof(a))
#define clr_false(a) memset(a,false,sizeof(a))
#define clr_queue(q) while(!q.empty()) q.pop()
#define clr_stack(s) while(!s.empty()) s.pop()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define dep(i, a, b) for (int i = a; i > b; i--)
#define repin(i, a, b) for (int i = a; i <= b; i++)
#define depin(i, a, b) for (int i = a; i >= b; i--)
#define pi 3.1415926535898
#define eps 1e-9
#define MOD 1000000007
#define MAXN (1<<10)+10
#define N 110
#define M
int n;
string s,ans,digit[N];
int main(){
    digit[0]=digit[1]="";
    digit[2]="2";
    digit[3]="3";
    digit[4]="223";
    digit[5]="5";
    digit[6]="35";
    digit[7]="7";
    digit[8]="2227";
    digit[9]="2337";
    cin>>n;
    cin>>s;
    ans.clear();
    rep(i,0,n){
        ans+=digit[s[i]-‘0‘];
    }
    sort(ans.begin(),ans.end());
    depin(i,slen(ans)-1,0){
        cout<<ans[i];
    }
    cout<<endl;
}
时间: 2024-08-09 19:54:09

Codeforces Round #292 Div1 A的相关文章

Codeforces Round #292 Div1 B

Problem 给一幅N×M的平面图G,其中 # 表示不可填方格: . 表示可填方格.现将1×2或2×1的小方格填充图G,要求图G可填方格全被填满,且无两小方格相互重叠.如果无法达到要求或有多种解法,输出 "Not unique",否则输出填好后的图G. Limits TimeLimit(ms):2000 MemoryLimit(MB):256 N,M∈[1,2000] Look up Original Problem From here Solution 二维拓扑排序. 1. 将所有

Codeforces Round #285 Div1 A and Div2 C

Problem 给一个图G,保证G是一个森林(坑!).图G含有N个点,给出每个点的两个属性:度数(degree).异或和(sum).度数表示该点与多少个点相连,异或和表示与其相连的点的编号的异或和(点编号从0开始,若度数为0则异或和为0).要求求出原图,输出边的个数和每条边两端的顶点. Limits Time Limit(ms): 1000 Memory Limit(MB): 256 N: [1, 2^16] degree: [0, N-1] Solution 由于G是森林,G的每一个连通图一定

Codeforces Round #290 Div1 A

Problem 给N串字符串Si,通常定义字典序大小关系为 'a'<'b'<'c'<......<'y'<'z',现要求重新定义大小关系使得对于任意 i,j(i<j)满足Si <Sj,输出大小关系(一串'a'-'z'的排列),或者输出不存在(任意大小关系都不能满足要求). Limits Time Limit(ms): 2000 Memory Limit(MB): 256 N: 100 |Si|: 100 Solution 用图论方法解决,发现满足拓扑关系.枚举相邻

Codeforces Round #290 Div1 B

Problem 有一只青蛙在x轴上跳,起初在原点,现有N种跳跃技能可以购买,每技能有两属性:跳跃长度Li 以及 花费Ci.若购买了第 i 种技能,则可以从 y 位置跳跃到 y+Li 或者 y-Li 位置,但需花费Ci 元.求最小花费使得青蛙可以跳到每一个整数点上,若无法做到,输出-1. Limits Time Limit(ms): 2000 Memory Limit(MB): 256 N: 300 Li: [1, 10^9] Ci: [1, 10^5] Solution 若购买了n个属性使得青蛙

[Codeforces Round #444 div1] C.DZY Loves Colors 【线段树】

题目链接:CF Round #444 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的区间完全被要求修改的区间包含时,就直接打上赋值的标记然后 return .但是这样这个节点中每个位置原先的值不同,需要进行的属性权值修改也就不同,是不能直接实现的.如果我们在节点表示的区间被修改的区间包含时,并不直接打标记 return ,而是当节点表示的区间被修改的区间完全包含而且这个节点中的每个

Codeforces Round #292 (Div. 1) B. Drazil and Tiles(拓扑排序)

题目地址:codeforces 292 B 用队列维护度数为1的点,也就是可以唯一确定的点,然后每次找v1,v2,并用v2来更新与之相连的点,如果更新后的点度数为1,就加入队列.若最后还有为"."的,说明无解或解不唯一. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #i

Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)

题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似topsort,'.'与上下左右的'.',的相连.从度为1的点作为突破口. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm> 3 #include <iostr

Codeforces Round #292 (Div. 2 Div. 1)

比赛链接:http://codeforces.com/contest/515  http://codeforces.com/contest/516 A. Drazil and Date time limit per test 1 second memory limit per test 256 megabytes Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. D

Codeforces Round #391 div1 757F (Dominator Tree)

首先先膜杜教orz 这里简单说一下支配树的概念 支配树是对一个有向图来讲的 规定一个起点s,如果s到v的路径上必须经过某些点u,那么离s最近的点u就是v的支配点 在树上的关系就是,v的父亲是u. 一般图的支配树需要使用tarjan算法,但是如果有向图是没有环的,可以采用另一种做法 按照拓扑序建立支配树,每次加点的时候,枚举能到它的所有点,求它们在当前支配树的最近公共祖先,那个点就是该点的支配点 这个题先建立一个最短路图,易知,这个图是没有环的有向图,所以建立支配树的时候就可以采用以上做法 orz