UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212566#3839. 小t爱算数(mul)ylq022101405ms13408kbC++111.1kb2024-10-19 11:40:302024-10-19 12:35:48

answer

#include <bits/stdc++.h>
using namespace std;
struct node{
	int zhengfu,zhi,xi;
	bool operator<(const node &t)const{
		if(zhi!=t.zhi) return zhi>t.zhi;
		return xi>t.xi;
	}
};
vector<node> one;
vector<node> two;
vector<node> mul;
int main(){
	int z,x;
	while(cin>>z){
		if(z!=-1){
			cin>>x;
			if(x!=0) one.push_back({x<0?0:1,z,abs(x)});
		}
		else break;
	}
	while(cin>>z){
		if(z!=-1){
			cin>>x;
			if(x!=0) two.push_back({x<0?0:1,z,abs(x)});
		}
		else break;
	}
	for(auto u:one){
		for(auto v:two){
			int f=0;
			if(u.zhengfu==v.zhengfu) f=1;
			mul.push_back({f,u.zhi+v.zhi,u.xi*v.xi});
		}
	}
	sort(mul.begin(),mul.end());
	mul.push_back({0,0,0});
	int ans;
	if(!mul[0].xi)ans-=mul[0].xi;
	else ans+=mul[0].xi;
	for(int i=0;i<mul.size()-1;i++){
		if(mul[i].xi!=mul[i+1].xi){
			if(mul[i].zhi==0) cout<<ans;
			else{
				if(ans<0) cout<<"-";
				else if(i>0) cout<<"+";
				if(ans!=1) cout<<ans;
				cout<<"x^"<<mul[i].zhi;
			}
		}
		else{
			if(!mul[i].xi)ans-=mul[i].xi;
			else ans+=mul[i].xi;
		}
	}
	return 0;
}

详细

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

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1256kb

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:

63x^20+63x^19+63x^18+63x^17+63x^17+63x^17+63x^16+63x^16+63x^16+63x^15+63x^15+63x^15+63x^14+63x^14+63...

result:

wrong answer 1st lines differ - expected: '63x^20-27x^19-63x^18+33x^17-40...146x^5+20x^4-43x^3+6x^2-...

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 1248kb

input:

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

output:

9x^8+15x^6+15x^4

result:

wrong answer 1st lines differ - expected: '9x^8-4x^4', found: '9x^8+15x^6+15x^4'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 1428kb

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:

126x^199+126x^198+126x^198+126x^197+126x^197+126x^197+126x^196+126x^196+126x^196+126x^196+126x^195+1...

result:

wrong answer 1st lines differ - expected: '-126x^199+1958x^198-5539x^197-...^4-8639x^3+3990x^2+2463x...

Test #4:

score: 0
Wrong Answer
time: 247ms
memory: 13408kb

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:

736791x^1999+736791x^1998+736791x^1998+736791x^1997+736791x^1997+736791x^1997+736791x^1996+736791x^1...

result:

wrong answer 1st lines differ - expected: '-736791x^1999-60050x^1998+3908...9x^3-646021x^2+537451x^1...

Test #5:

score: 0
Wrong Answer
time: 223ms
memory: 13404kb

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:

736791x^1999+736791x^1998+736791x^1998+736791x^1997+736791x^1997+736791x^1997+736791x^1996+736791x^1...

result:

wrong answer 1st lines differ - expected: '-736791x^1999-60050x^1998+3908...9x^3-646021x^2+537451x^1...

Test #6:

score: 0
Wrong Answer
time: 234ms
memory: 13404kb

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:

736791x^2000+736791x^1999+736791x^1999+736791x^1998+736791x^1998+736791x^1998+736791x^1997+736791x^1...

result:

wrong answer 1st lines differ - expected: '-736791x^2000-60050x^1999+3908...7x^3+221500x^2-144211x^1...

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 1248kb

input:

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

output:

+3x^1

result:

wrong answer 1st lines differ - expected: 'x^4-x^3+x^1', found: '+3x^1'

Test #8:

score: 0
Wrong Answer
time: 235ms
memory: 13408kb

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:

473709x^1998+473709x^1997+473709x^1997+473709x^1996+473709x^1996+473709x^1996+473709x^1995+473709x^1...

result:

wrong answer 1st lines differ - expected: '473709x^1998-779642x^1997-6059...26x^3-912464x^2+110065x^...

Test #9:

score: 0
Wrong Answer
time: 230ms
memory: 13408kb

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:

608478x^1999+608478x^1998+608478x^1998+608478x^1997+608478x^1997+608478x^1997+608478x^1996+608478x^1...

result:

wrong answer 1st lines differ - expected: '608478x^1999-492227x^1998+1483...9x^3-605960x^2-779642x^1...

Test #10:

score: 0
Wrong Answer
time: 236ms
memory: 13404kb

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:

256519x^2000+256519x^1999+256519x^1999+256519x^1998+256519x^1998+256519x^1998+256519x^1997+256519x^1...

result:

wrong answer 1st lines differ - expected: '-256519x^2000-144211x^1999+221...66x^3+390877x^2-60050x^1...