我需要求助,40分,后三个点WA
查看原帖
我需要求助,40分,后三个点WA
1045401
hard_shuati楼主2024/9/7 07:49

代码如下:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100005], b[100005], c[100005];
string mul(string a1,string b1){
	int i,j=0;
	string a3="";
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	memset(c, 0, sizeof(c));
	int p=a1.size();
	int q=b1.size();
	for(i=p-1; i>=0; i--){
		a[++j]=a1[i]-'0';
	}
	j=0;
	for(i=q-1; i>=0; i--){
		b[++j]=b1[i]-'0';
	}
	//放进数组
	for(i=1;i<=p;i++){
		for(j=1;j<=q;j++)
			c[i+j-1]+=a[i]*b[j];
	}//相乘
	for(i=1;c[i];i++){
		if(c[i]>=10){
			c[i+1]+=c[i]/10;
			c[i]%=10;
		}
	}
	//处理进位
	for(;i>1;i--){
		if(c[i])break;
	}//处理前导零
	for(;i>=1;i--){
		a3.push_back((char)(c[i]+'0'));
	}//处理答案为string
	return a3;//返回
}
//位数:1000位*1000位 
string n;
int k;
vector <int> canbe [10];
int sol[10];
bool vis[10];
string answer="1";
int dfs(int x) {
	vis[x]=1;
	int ans=0;
	for(int p : canbe[x]) {
		if(!vis[p]) {
			ans+=dfs(p);
		}
	}
	vis[x]=0;
	return ans+1;
}
main() {
	cin >> n >> k;
	for(int i=1; i<=k; i++) {
		int p, q; cin >> p >> q;
		canbe[p].push_back(q);
	}
	for(int i=0; i<10; i++) {
		sol[i]=dfs(i);
	}
	for(int i=0; i<(int)n.size(); i++) {
		int ch=n[i];
		ch-='0';
		string qq="1";
		qq[0]=sol[ch]+'0';
		answer=mul(answer, qq);
	}
	cout << answer;
}

(马蜂有点丑)

@General0826 菜德帮帮我

2024/9/7 07:49
加载中...