第一场ATcoder就遇到测试样例出问题取消本场积分的事情,呜呜呜~~一份题解证明我来过!ABC水过前三道,排名575.
上周的比赛,因为最后一题加上拖延症,还是终于在本周比赛开始前来写这个解题报告了。第一场体验还是不错的,后来发现有题解值得表扬
A - Maximize the Formula
https://beta.atcoder.jp/contests/abc110/tasks/abc110_a
题意:给三个个位数,将其中两个拼成两位数再加上第三个数,得到结果,输出可能的最大结果。
思路:找到最大的数乘以10,然后把剩下两个加起来。
#include
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
int sum=0;
if(a>=b&&a>=c) sum=a*10+b+c;
else if(b>=a&&b>=c) sum=b*10+a+c;
else sum=c*10+a+b;
cout<
B - 1 Dimensional World's Tale
https://beta.atcoder.jp/contests/abc110/tasks/abc110_b
题意:给两堆整数,如果有交集则发生战争。
思路:输入时候记录第一堆的最大数和第二堆的最小数,最后进行比较。
#include
using namespace std;
int main()
{
int n,m,x,y;
cin>>n>>m>>x>>y;
int xx,yy;
for(int i=0;i>xx;
if(xx>x) x=xx;
}
for(int i=0;i>yy;
if(yy
C - String Transformation
https://beta.atcoder.jp/contests/abc110/tasks/abc110_c
思路:两个等长字符串,可以对第一个字符串操作,每次操作指定两个不同的小写字母,将第一个字符串中每个这两个字母都变成另一个。判断是否能通过变换将第一个字符串变成第二个。
思路:s和t字符串都是用一个长度为26的辅助字符串来记录,遍历s和t字符串,同一个字母对应的另一个字符串相同位置上的字母要保持一样,否则不可能。
#include
#include
#include
using namespace std;
char s[200005],t[200005];
int main()
{
cin>>s>>t;
int fs[26],ft[26];
memset(fs,-1,sizeof(fs));
memset(ft,-1,sizeof(ft));
int l=strlen(s);
int flag=0;
for(int i=0;i
D - Factorization
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400
points
Problem Statement
You are given positive integers N and M
How many sequences a of length N consisting of positive integers satisfy a1×a2×...×aN=M? Find the count modulo 10^9+7
Here, two sequences a′ and a′′ are considered different when there exists some i such that a′i≠a′′i
Constraints
- All values in input are integers.
- 1≤N≤105
- 1≤M≤109
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9+7.
Sample Input 1
2 6
Sample Output 1
4
Four sequences satisfy the condition: {a1,a2}={1,6},{2,3},{3,2} and {6,1}.
思路:参考了网上各路大神的,我终于理解这道题怎么做了。将
M分解,记录成若干素数的个数,问题就变成了将这些素数分成N份,为空的份数放1。也就是假设M分解素因数有k种,每个素数个数为a1,a2...ak,等同于有k种不同小球,每个小球a1,a2...ak个,同种小球相同,问将这些小球放到N的不同的桶里,有多少种方法,允许空桶。
首先考虑将a个相同小球放到N个不同桶中的方法,然后将这k堆的方案数相乘即可。对于一堆相同小球,使用隔板法计算,因为允许有空桶,增加N个小球变成没有空桶的情况,可得共C(a+n-1,n-1)种方法。
代码计算的时候为了减少循环次数,使用了sqet(m),这样可能会有一个剩余的素数没有算到,最后进行了处理。
注意:思路上没有什么问题了,主要就是计算C这个公式。
预处理,将阶乘计算出来打表记录。C的计算中有除法过程,因为计算中有求余,所以要使用逆元,又重新学了一遍。逆元
#include
#include
using namespace std;
#define MOD 1000000007
long long f[1000005];
long long g[100005];
long long inv[1000005];
long long q_pow(long long n,long long m)
{
int res=1;
while(m)
{
if(m&1)
{
res=(res*n)%MOD;
}
n=(n*n)%MOD;
m=m>>1;
}
return res;
}
void fac()
{
f[0]=1;
inv[0]=1;
for(long long i=1;i<=1000000;i++)
{
f[i]=(f[i-1]*i)%MOD;
}
inv[1000000]=q_pow(f[1000000],MOD-2);
for(long long i=1000000-1;i>0;i--)
{
inv[i]=(inv[i+1]*(i+1))%MOD;
}
}
long long c(long long n,long long m)
{
long long res=((f[n]*inv[n-m])%MOD*inv[m])%MOD;
return res;
}
int main()
{
fac();
long long n,m;
cin>>n>>m;
long long p=0;
long long lim=sqrt(m);
for(int i=2;i<=lim;i++)
{
if(m%i==0)
{
g[p]=0;
while(m%i==0)
{
g[p]++;
m=m/i;
}
p++;
}
}
long long ans=1;
for(int i=0;i