fish_love_cat @ 2023-04-25 18:38:06
RT
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int a[10005]={},b[10005]={},c[10005]={};
int n,x,ans=0;
cin>>n>>x;
a[1]=1;
int leng=sizeof(a)/sizeof(int);
bool f=false;
for(int i=2;i<=n;i++){
if(!f){
int xin=i;
int m=1;
while(xin){
b[m++]=xin%10;
xin/=10;
}
int s1len=leng;
int s2len=m-1;
for(int i=1;i<=s1len;i++){
for(int j=1;j<=s2len;j++){
c[i+j-1]+=a[i]*b[j];
c[i+j]+=c[i+j-1]/10;
c[i+j-1]%=10;
}
}
leng=s1len+s2len;
if(c[leng]!=0){
leng++;
}
f=true;
}else{
int xin=i;
int m=1;
while(xin){
b[m++]=xin%10;
xin/=10;
}
int s1len=leng;
int s2len=m-1;
for(int i=1;i<=s1len;i++){
for(int j=1;j<=s2len;j++){
a[i+j-1]+=c[i]*b[j];
a[i+j]+=a[i+j-1]/10;
a[i+j-1]%=10;
}
}
leng=s1len+s2len;
if(a[leng]!=0){
leng++;
}
}
f=false;
}
if(!f){
for(int i=0;i<leng;i++){
if(a[i]==x) ans++;
}
}else{
for(int i=0;i<leng;i++){
if(c[i]==x) ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
by fish_love_cat @ 2023-04-25 18:54:25
新的代码
但还是 0 分,全 WA……
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int a[10005]={},b[10005]={},c[10005]={};
int n,x,ans=0;
cin>>n>>x;
a[1]=1;
int leng=1;
bool f=false;
for(int i5=2;i5<=n;i5++){
if(!f){
int xin=i5;
int m=1;
while(xin){
b[m++]=xin%10;
xin/=10;
}
int s1len=leng;
int s2len=m-1;
for(int i=1;i<=s1len;i++){
for(int j=1;j<=s2len;j++){
c[i+j-1]+=a[i]*b[j];
c[i+j]+=c[i+j-1]/10;
c[i+j-1]%=10;
}
}
leng=s1len+s2len;
if(c[leng]!=0){
leng++;
}
f=true;
}else{
int xin=i5;
int m=1;
while(xin){
b[m++]=xin%10;
xin/=10;
}
int s1len=leng;
int s2len=m-1;
for(int i=1;i<=s1len;i++){
for(int j=1;j<=s2len;j++){
a[i+j-1]+=c[i]*b[j];
a[i+j]+=a[i+j-1]/10;
a[i+j-1]%=10;
}
}
leng=s1len+s2len;
if(a[leng]!=0){
leng++;
}
f=false;
}
}
if(!f){
for(int i=0;i<leng;i++){
if(a[i]==x) ans++;
}
}else{
for(int i=0;i<leng;i++){
if(c[i]==x) ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
by fish_love_cat @ 2023-04-25 20:52:12
修改至 70 分
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int a[10005]={},b[10005]={},c[10005]={};
int n,x,ans=0;
cin>>n>>x;
a[1]=1;
int leng=1;
bool f=false;
for(int i5=2;i5<=n;i5++){
if(!f){
memset(c,0,sizeof(c));
int xin=i5;
int m=1;
while(xin){
b[m++]=xin%10;
xin/=10;
}
int s1len=leng;
int s2len=m-1;
for(int i=1;i<=s1len;i++){
for(int j=1;j<=s2len;j++){
c[i+j-1]+=a[i]*b[j];
c[i+j]+=c[i+j-1]/10;
c[i+j-1]%=10;
}
}
leng=s1len+s2len;
if(c[leng]!=0){
leng++;
}
f=true;
}else{
memset(a,0,sizeof(a));
int xin=i5;
int m=1;
while(xin){
b[m++]=xin%10;
xin/=10;
}
int s1len=leng;
int s2len=m-1;
for(int i=1;i<=s1len;i++){
for(int j=1;j<=s2len;j++){
a[i+j-1]+=c[i]*b[j];
a[i+j]+=a[i+j-1]/10;
a[i+j-1]%=10;
}
}
leng=s1len+s2len;
if(a[leng]!=0){
leng++;
}
f=false;
}
}
if(!f){
for(int j=0;j<leng;j++){
if(a[j]==x) ans++;
}
}else{
for(int j=0;j<leng;j++){
if(c[j]==x) ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
by fish_love_cat @ 2023-04-26 07:19:33
已解决
遍历写错了qwq
by UKError @ 2023-04-26 22:26:46
6