336 条题解
-
0denverjin LV 7 @ 2016-09-18 20:16:25
#include <cstdio>
#include <cstring>
using namespace std;
struct Bigint
{
int n,a[20005];
Bigint()
{
n = 0;
memset(a,0,sizeof(a));
}
void operator = (const char string[10005])
{
n = strlen(string);
for (int i = 0;i < n;i++)
a[i] = string[n-1-i]-'0';
}
Bigint operator * (const Bigint &x)
{
Bigint t;t.n = n+x.n-1;
for (int i = 0;i < n;i++)
for (int j = 0;j < x.n;j++)
t.a[i+j] += a[i]*x.a[j];
for (int i = 0;i < t.n;i++)
{
t.a[i+1] += t.a[i] / 10;
t.a[i] %= 10;
}
if (t.a[t.n]) t.n++;
return t;
}
};
int main()
{
char x[10005],y[10005];
scanf("%s%s",x,y);
Bigint a,b;
a = x;
b = y;
Bigint ans;
ans = a*b;
for (int i = ans.n-1;i >= 0;i--)
printf("%d",ans.a[i]);
printf("\n");
return 0;
} -
02016-08-12 18:22:48@
var s1,s2,s:ansistring; a,b,c:array[0..20005] of longint; i,len1,len2,len,t,j:longint; begin readln(s1); readln(s2); len1:=length(s1); len2:=length(s2); fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); for i:=len1 downto 1 do a[length(s1)-i+1]:=ord(s1[i])-48; for i:=len2 downto 1 do b[length(s2)-i+1]:=ord(s2[i])-48; for i:=1 to len1 do for j:=1 to len2 do c[i+j-1]:=c[i+j-1]+a[i]*b[j]; len:=len1+len2; for i:=1 to len do begin c[i+1]:=c[i+1]+c[i] div 10; //进位 c[i]:=c[i] mod 10 end; while c[len]=0 do dec(len); t:=c[len]; while t>9 do begin c[len]:=t mod 10; t:=t div 10; inc(len); end; for j:=len downto 1 do write(c[j]); end.
遥想当年的pascal
-
02016-07-27 21:49:19@
人生苦短,人生苦短
x = int(raw_input())
y = int(raw_input())
print x*y
-
02016-07-20 03:51:49@
#include<cstdio> #include<cstring> using namespace std; char str1[12000],str2[12000]; int a[12000],b[12000],c[24000]; int main(void) { int temp; gets(str1);gets(str2); if(str1[0]=='0' || str2[0]=='0'){printf("0");return 0;} int lena=strlen(str1); int lenb=strlen(str2); int len=22000; for(int i=0;i<lena;i++) a[lena-1-i]=str1[i]-'0'; for(int i=0;i<lenb;i++) b[lenb-1-i]=str2[i]-'0'; for(int i=0;i<lena;i++) for(int j=0;j<lenb;j++) { c[i+j]+=a[i]*b[j]; temp=c[i+j]/10; c[i+j+1]+=temp; c[i+j]-=temp*10; if(c[i+j+1]>=10){c[i+j+1]-=10;c[i+j+2]++;} } for(len=22000;len>=0&&c[len]==0;len--); len++; for(int i=len-1;i>=0;i--)printf("%d",c[i]); return 0; }
-
02016-07-12 21:46:14@
数组开得比题中大很多才能过
#include <cstdio>
#include <cstring>int read(int a[]){
char c[10001];
scanf("%s",c);
int n=1,len=strlen(c),k=1;
for(int i=0;i<len;i++){
if(k==10000){
k=1;
n++;
}
a[n]+=k*(c[len-i-1]-'0');
k*=10;
}
a[0]=n;
}void multx(int a[],int b[],int c[]){
for(int i=1;i<=a[0];i++)
for(int j=1;j<=b[0];j++){
c[i+j-1]+=a[i]*b[j];
c[i+j]+=c[i+j-1]/10000;
c[i+j-1]%=10000;
}
int len=a[0]+b[0];
while(c[len]==0&&len>1)
len--;
c[0]=len;
}void output(int a[]){
printf("%d",a[a[0]]);
for(int i=a[0]-1;i>=1;i--)
printf("%04d",a[i]);
}int main(){
int s1[5000]={0},s2[5000]={0},s[6000]={0};
read(s1);
read(s2);
multx(s1,s2,s);
output(s);return 0;
} -
02016-07-09 12:20:04@
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[12000],b[12000],c[12000];
char al[12000],bl[12000];
int main()
{
cin>>al;cin>>bl;
int lena=strlen(al),lenb=strlen(bl),lenc=lena+lenb,x;
for(int i=0;i<=lena-1;i++)
a[lena-i]=al[i]-'0';
for(int i=0;i<=lenb-1;i++)
b[lenb-i]=bl[i]-'0';
for(int i=1;i<=lena;i++)
{
x=0;
for(int j=1;j<=lenb;j++)
{
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;
}
while(c[lenc]==0&&lenc>1)
lenc--;
for(int i=lenc;i>=1;i--)
cout<<c[i];
return 0;
} -
02016-04-11 22:38:49@
FFT大法好!!!
FFT大法好!!!
FFT大法好!!!
FFT大法好!!!
FFT大法好!!!测试数据 #0: Accepted, time = 0 ms, mem = 9224 KiB, score = 25
测试数据 #1: Accepted, time = 0 ms, mem = 9232 KiB, score = 25
测试数据 #2: Accepted, time = 15 ms, mem = 9224 KiB, score = 25
测试数据 #3: Accepted, time = 0 ms, mem = 9224 KiB, score = 25
Accepted, time = 15 ms, mem = 9232 KiB, score = 100FFT大法好!!!
FFT大法好!!!
FFT大法好!!!
FFT大法好!!!
FFT大法好!!!#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<list>
using namespace std;template<class T>
inline T read(T &x){
int fu=1;
x=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')fu=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
x*=fu;
return x;
}const double pi=acos(-1.0);
struct complex{
double r,i;
complex(double _r=0.0,double _i=0.0){
r=_r;
i=_i;
}
complex operator + (const complex &a){
return complex(r+a.r,i+a.i);
}
complex operator - (const complex &a){
return complex(r-a.r,i-a.i);
}
complex operator * (const complex &a){
return complex(r*a.r-i*a.i,r*a.i+i*a.r);
}
}x[233333],y[233333];
char s1[233333],s2[233333];
int l=1,l1,l2,s[233333];inline void change(complex x2[],int len){
for(int i=1,j=len/2;i<len-1;i++){
if(i<j)swap(x2[i],x2[j]);
int k=len/2;
while(j>=k){
j-=k;
k/=2;
}
if(j<k)j+=k;
}
return;
}inline void fft(complex x2[],int len,int p){
change(x2,len);
for(int i=2;i<=len;i<<=1){
complex a(cos(-p*2*pi/i),sin(-p*2*pi/i));
for(int j=0;j<len;j+=i){
complex b(1,0);
for(int k=j;k<j+i/2;k++){
complex c=x2[k],d=b*x2[k+i/2];
x2[k]=c+d;
x2[k+i/2]=c-d;
b=b*a;
}
}
}
if(p==-1)for(int i=0;i<len;i++)x2[i].r/=len;
return;
}int main(){
//freopen("power.in","r",stdin);
//freopen("power.out","w",stdout);scanf("%s%s",s1,s2);
l1=strlen(s1);
l2=strlen(s2);
while(l<l1*2||l<l2*2)l<<=1;
for(int i=0;i<l1;i++)x[i]=complex(s1[l1-1-i]-'0',0);
for(int i=l1;i<l;i++)x[i]=complex(0,0);
for(int i=0;i<l2;i++)y[i]=complex(s2[l2-1-i]-'0',0);
for(int i=l2;i<l;i++)y[i]=complex(0,0);
fft(x,l,1);
fft(y,l,1);
for(int i=0;i<l;i++)x[i]=x[i]*y[i];
fft(x,l,-1);
for(int i=0;i<l;i++)s[i]=(int)(x[i].r+0.5);
for(int i=0;i<l;i++){
s[i+1]+=s[i]/10;
s[i]%=10;
}
l=l1+l2-1;
while(s[l]<=0&&l)l--;
for(int i=l;i>=0;i--)printf("%c",s[i]+'0');
printf("\n");//fclose(stdin);
//fclose(stdout);
return 0;
}FFT大法好!!!
FFT大法好!!!
FFT大法好!!!
FFT大法好!!!
FFT大法好!!! -
02016-02-21 11:13:59@
import java.io.*; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in))); System.out.println(sc.nextBigInteger().multiply(sc.nextBigInteger())); } }
-
02016-02-05 18:29:49@
一个菜鸟人生中不多的一次1A,,,,,,
希望对初学者有用吧,大神们不要笑话我,粘代码
#include<iostream>
#include<cstring>
using namespace std;
char in[2][10007], out[20007];
int a[20007] = {0}, b[20007] = {0}, tr[2][20007] = {0};
int x = 0;
void mto1(int m, int n)
{
if(in[0][n - 1] == '\0')
{
tr[0][n] = x;
tr[1][m + n - 1] += tr[0][n];
if(tr[1][m + n - 1] >= 10)
{
tr[1][m + n]++;
tr[1][m + n - 1] -= 10;
}
return;
}
tr[0][n] = x + a[n] * b[m];
x = tr[0][n] / 10;
tr[0][n] -= x * 10;
tr[1][m + n - 1] += tr[0][n];
if(tr[1][m + n - 1] >= 10)
{
tr[1][m + n]++;
tr[1][m + n - 1] -= 10;
}
mto1(m, n + 1);
return;
}
void mtom()
{
for(int i = 1; i <= strlen(in[1]); i++)
{
memset(tr[0], 0, sizeof(tr[0]));
x = 0;
mto1(i, 1);
}
}
int main()
{
cin >> in[0] >> in[1];
int l0 = strlen(in[0]);
int l1 = strlen(in[1]);
for(int i = 0; i <= l0; i++)
a[i + 1] = in[0][l0 - i - 1] - 48;
for(int i = 0; i <= l1; i++)
b[i + 1] = in[1][l1 - i - 1] - 48;
mtom();
int ct = 0;
for(int i = 20007; i >= 1; i--)
{
if(tr[1][i] == 0)
ct++;
else break;
}
for(int i = 20007 - ct; i >= 1; i--)
cout << tr[1][i];
return 0;
} -
02015-11-22 10:07:56@
import java.io.*;
import java.util.Scanner;public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a + b);
}
} -
02015-11-22 10:05:18@
import java.io.*;
import java.util.Scanner;public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a * b);
}
} -
02015-11-04 12:52:53@
#include <iostream>
#include <string>using namespace std;
void Proc1();
class Num
{
public:
Num();
Num(short);
Num(string&);
Num(Num&);
~Num();
Num operator*(const Num&num_p) const;
friend std::ostream& operator<<(std::ostream&os, const Num&n);
private:
int* num_indigit;
short digit;
};Num::Num()
{
digit = 1;
num_indigit = new int[digit];
num_indigit[0] = 0;}
Num::Num(short digit_num)
{
digit = digit_num;
num_indigit = new int[digit];
for (int i = 0; i < digit; i++)
{
num_indigit[i] = 0;
}
}
Num::Num(string&str_p)
{
digit = str_p.size();
num_indigit = new int[digit];
for (short i = 0; i < digit; i++)
num_indigit[i] = (str_p[digit-1-i]-'0');
}
Num::Num(Num& num_cpy)
{
digit = num_cpy.digit;
num_indigit = new int[digit];
for (short i = 0; i < num_cpy.digit; i++)
num_indigit[i] = num_cpy.num_indigit[i];
}Num::~Num()
{}
Num Num::operator*(const Num & num_p) const
{
short digit1 = digit, digit2 = num_p.digit;
Num result(digit1 + digit2);for (int i = 0; i < digit2; i++)
for (int j = 0; j < digit1; j++)
result.num_indigit[i + j] += num_indigit[j] * num_p.num_indigit[i];for (int i = 0; i < digit1 + digit2-1; i++)
{
result.num_indigit[i + 1] += result.num_indigit[i] / 10;
result.num_indigit[i] %= 10;
}
while (!result.num_indigit[result.digit - 1]) result.digit--;return result;
}
std::ostream& operator<<(std::ostream&os, const Num&num_show)
{
char *ctmp = new char[num_show.digit+1];
for (int i = 0; i < num_show.digit; i++)
{
ctmp[i] = char(num_show.num_indigit[num_show.digit-1-i]+'0');
}
*(ctmp + num_show.digit) = '\0';
os << ctmp;
return os;
}//-Main Procedure-感觉自己萌萌哒
int main()
{
Proc1();
return 0;
}
void Proc1()
{
using namespace std;
string p, q;
cin >> p;
cin >> q;
Num num_p = Num(p);
Num num_q = Num(q);
Num result;
result = num_p*num_q;
cout << result<<endl;
} -
02015-10-26 13:56:14@
。。注意10000位啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊。。
#include<stdio.h>
#include<string.h>
struct hp
{
int z[20005];
};hp cheng(hp a,hp b)
{
hp c;
c.z[0]=a.z[0]+b.z[0];
for (int i=1;i<=c.z[0];i++) c.z[i]=0;
for (int i=1;i<=b.z[0];i++)
for (int j=1;j<=a.z[0];j++)
{
c.z[i+j-1]+=a.z[j]*b.z[i];
c.z[i+j]+=c.z[i+j-1]/10;
c.z[i+j-1]%=10;
}
while (c.z[0]>1&&c.z[c.z[0]]==0) c.z[0]--;
return c;
}hp a,b,c,d,e,f;
char s[260];
int main()
{
int len,x;
scanf("%s",s);
len=strlen(s);
a.z[0]=len;
for (int i=1;i<=len;i++) a.z[i]=s[len-i]-'0';
scanf("%s",s);
len=strlen(s);
b.z[0]=len;
for (int i=1;i<=len;i++) b.z[i]=s[len-i]-'0';
d=cheng(a,b);
for (int i=d.z[0];i>=1;i--)
printf("%d",d.z[i]);
return 0;
} -
02015-10-02 13:34:37@
#include <iostream>
#include <string>
#include <vector>using namespace std;
int main()
{
string xxx,yyy;
cin>>xxx>>yyy;vector<int>x;
vector<int>y;
int i,j;
j=xxx.length();
for(i=0;i<j;++i)
{
x.push_back(xxx[j-i-1]-'0');
}
j=yyy.length();
for(i=0;i<j;++i)
{
y.push_back(yyy[j-i-1]-'0');
}vector<int>ans;
int xn,yn;
int k,k1;
xn=x.size();
yn=y.size();
for(i=0;i<xn;++i)
{
for(j=0;j<yn;++j)
{
k=i+j+1;
while(ans.size()<=k)ans.push_back(0);
ans[i+j]+=(x[i]*y[j]);
ans[i+j+1]+=ans[i+j]/10;
ans[i+j]%=10;
}
}
k=ans.size();
k1=1;
for(i=0;i<k;++i)
{
if(ans[k-1-i]==0)k1++;
else break;
}
for(i=0;k-k1-i>=0;++i)
{
cout<<ans[k-k1-i];
}
return 0;
} -
02015-09-23 20:48:16@
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a1[100000],b1[100000];
int a[1000000],b[10000000],c[10000000],lena,lenb,lenc,i,j,x;
int main()
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
gets(a1);gets(b1);
lena=strlen(a1);lenb=strlen(b1);
for (i=0;i<=lena-1;i++) a[lena-i]=a1[i]-48;
for (i=0;i<=lenb-1;i++) b[lenb-i]=b1[i]-48;
for (i=1;i<=lena;i++)
{
x=0; //用于存放进位
for (j=1;j<=lenb;j++) //对乘数的每一位进行处理
{
c[i+j-1]=a[i]*b[j]+x+c[i+j-1]; x=c[i+j-1]/10;
c[i+j-1] %= 10;
}
c[i+lenb]=x; //进位
}
lenc=lena+lenb;
while (c[lenc]==0&&lenc>1) //删除前导0
lenc--;
for (i=lenc;i>=1;i--)
cout<<c[i];
cout<<endl;
return 0;
} -
02015-09-04 12:13:05@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)
#define clr(x,c) memset(x,c,sizeof(x))
char al[10000],bl[10000];
int a[10005],b[10005],c[100000000];
int main(){
scanf("%s%s",al,bl);
int lena=strlen(al);
int lenb=strlen(bl);
rep(i,lena)
a[lena-i]=al[i]-'0';
rep(i,lenb)
b[lenb-i]=bl[i]-'0';
reps(i,lena){
int x=0;
reps(j,lenb){
int temp=a[i]*b[j]+x;
c[i+j-1]+=temp;
x=c[i+j-1]/10;
c[i+j-1]=c[i+j-1]%10;
}
c[i+lenb]=x;
}
int cur=lena+lenb;
if(c[cur]==0) cur--;
while(cur){
cout<<c[cur];
cur--;
}
return 0;
} -
02015-08-26 11:46:52@
import java.io.*;
import java.util.*;
import java.math.*;public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while(cin.hasNext()) {
BigInteger a = cin.nextBigInteger();
BigInteger b = cin.nextBigInteger();
System.out.println(a.multiply(b));
}
}
} -
02015-08-13 10:22:58@
#include <cstdio>
#include <cstring>
using namespace std;
struct Bigint
{
int n,a[20005];
Bigint()
{
n = 0;
memset(a,0,sizeof(a));
}
void operator = (const char string[10005])
{
n = strlen(string);
for (int i = 0;i < n;i++)
a[i] = string[n-1-i]-'0';
}
Bigint operator * (const Bigint &x)
{
Bigint t;t.n = n+x.n-1;
for (int i = 0;i < n;i++)
for (int j = 0;j < x.n;j++)
t.a[i+j] += a[i]*x.a[j];
for (int i = 0;i < t.n;i++)
{
t.a[i+1] += t.a[i] / 10;
t.a[i] %= 10;
}
if (t.a[t.n]) t.n++;
return t;
}
};
int main()
{
char x[10005],y[10005];
scanf("%s%s",x,y);
Bigint a,b;
a = x;
b = y;
Bigint ans;
ans = a*b;
for (int i = ans.n-1;i >= 0;i--)
printf("%d",ans.a[i]);
printf("\n");
return 0;
} -
02015-08-11 09:57:00@
Java:
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args){
BigInteger a,b;
Scanner in=new Scanner(System.in);
a=in.nextBigInteger();
b=in.nextBigInteger();
System.out.println(a.multiply(b));
}
} -
02015-07-18 10:22:25@
#include<stdio.h>
#include<string.h>
#define N 500
int main()
{
int a[N]={0},b[N]={0},c[N],la,lb,i,j,l;
char a1[N],b1[N];
gets(a1);
la=strlen(a1);
gets(b1);
lb=strlen(b1);
l=la+lb;
for(i=0;i<la;i++)
a[i]=a1[la-i-1]-'0';
for(i=0;i<lb;i++)
b[i]=b1[lb-i-1]-'0';
if(b[lb-1]==0)
printf("0");
for(i=0;i<la;i++)
for(j=0;j<lb;j++)
{
c[i+j]=c[i+j]+a[i]*b[j];
c[i+j+1]=c[i+j+1]+c[i+j]/10;
c[i+j]=c[i+j]%10;
}
while(c[l-1]==0)
l--;
for(i=l-1;i>=0;i--)
printf("%d",c[i]);
return 0;
}