UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212542#3839. 小t爱算数(mul)1855016168500ms0kbC++1.4kb2024-10-19 11:02:322024-10-19 12:34:44

answer

#include<bits/stdc++.h>
using namespace std;
long long a[1005],b[1005],n;
long long c[1005],d[1005],m;
long long x[1005],y[1005],ansn;
long long pd[1005];
signed main(){
	freopen("mul.in","r",stdin);
    freopen("mul.out","w",stdout);
	long long xx=0;
	while(1){
		if(n%2==1){
			b[n/2+1]=xx;
		}
		else{
			a[n/2]=xx;
		}
		n++;
		cin>>xx;
		if(xx==-1 && n%2==1){
			break;
		}
	}
	xx=0;
    while(1){
		if(m%2==1){
			d[m/2+1]=xx;
		}
		else{
			c[m/2]=xx;
		}
		m++;
		cin>>xx;
		if(xx==-1 && m%2==1){
			break;
		}
	}
	n--;
	m--;
	n/=2;
	m/=2;
	for(long long i=1;i<=n;i++){
		for(long long j=1;j<=m;j++){
			ansn++;
			x[ansn]=a[i]*c[j];
			y[ansn]=b[i]+d[j];
		}
	}
	for(long long i=1;i<=ansn;i++){
		for(long long j=1;j<=ansn;j++){
		   if(y[i]>y[j]){
		   	swap(y[i],y[j]);
		   	swap(x[i],x[j]);
		   }	
		}
	}
	for(long long i=2;i<=ansn;i++){
		if(y[i]==y[i-1]){
			y[i-1]=0;
			x[i]+=x[i-1];
			x[i-1]=0;
			pd[i-1]=1;
		}
	}
	long long firstt=0;
	for(long long i=1;i<=ansn;i++){
		if(pd[i]==0){
			if(y[i]==0){
				if(firstt==0){
					cout<<x[i];
					firstt=1;
				}
				else if(x[i]<0){
					cout<<x[i];
				}
				else{
					cout<<"+"<<x[i];
				}
			}
			else if(firstt==0){
				cout<<x[i]<<"x^"<<y[i];
				firstt=1;
			}
			else{
				if(x[i]<0){
					cout<<x[i]<<"x^"<<y[i];
				}
				else{
					cout<<"+"<<x[i]<<"x^"<<y[i];
				}
			}
		}
	}
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Dangerous Syscalls

input:

10 -7 9 3 7 4 6 -3 4 2 3 -7 2 -7 0 -3 -1
10 -9 8 9 7 -6 6 7 5 -2 3 -9 2 -9 1 7 0 3 -1

output:


result:


Test #2:

score: 0
Dangerous Syscalls

input:

4 3 2 -2 -1
4 3 2 2 -1

output:


result:


Test #3:

score: 0
Dangerous Syscalls

input:

100 -7 99 73 98 30 97 44 96 -23 95 -40 94 92 93 -87 92 -27 91 40 90 -3 89 -9 88 -60 87 99 86 -16 85 ...

output:


result:


Test #4:

score: 0
Dangerous Syscalls

input:

1000 -807 999 73 998 930 997 544 996 -923 995 -440 994 492 993 -987 992 -327 991 840 990 -303 989 -7...

output:


result:


Test #5:

score: 0
Dangerous Syscalls

input:

1000 -807 999 73 998 930 997 544 996 -923 995 -440 994 492 993 -987 992 -327 991 840 990 -303 989 -7...

output:


result:


Test #6:

score: 0
Dangerous Syscalls

input:

1000 -807 999 73 998 930 997 544 996 -923 995 -440 994 492 993 -987 992 -327 991 840 990 -303 989 -7...

output:


result:


Test #7:

score: 0
Dangerous Syscalls

input:

3 1 2 -1 0 1 -1
1 1 -1

output:


result:


Test #8:

score: 0
Dangerous Syscalls

input:

999 -807 998 73 997 930 996 544 995 -923 994 -440 993 492 992 -987 991 -327 990 840 989 -303 988 -70...

output:


result:


Test #9:

score: 0
Dangerous Syscalls

input:

0 -807 1 73 2 930 3 544 4 -923 5 -440 6 492 7 -987 8 -327 9 840 10 -303 11 -709 12 -560 13 99 14 -81...

output:


result:


Test #10:

score: 0
Dangerous Syscalls

input:

0 -807 1 73 2 930 3 544 4 -923 5 -440 6 492 7 -987 8 -327 9 840 10 -303 11 -709 12 -560 13 99 14 -81...

output:


result: