# Codeforces Round #750 (Div. 2) D. Vupsen, Pupsen and 0(Codeforces Round #750 (Div. 2) D. Vupsen, Pupsen and 0)-其他

## Codeforces Round #750 (Div. 2) D. Vupsen, Pupsen and 0(Codeforces Round #750 (Div. 2) D. Vupsen, Pupsen and 0)

AC代码：

``````#include<bits/stdc++.h>

using namespace std;

int main(){
int n,T;
scanf("%d",&T);

while(T --){
scanf("%d",&n);
if(n % 2 == 0){
int a,b;

for(int i = 0;i < n;i += 2){
scanf("%d%d",&a,&b);
printf("%d %d ",-b,a);
}
}
else {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);

if(a + b != 0){
printf("%d %d %d ",-c,-c,a + b);
}

else if(a + c != 0){
printf("%d %d %d ",-b,a + c,-b);
}
else{
printf("%d %d %d ",b + c,-a,-a);
}

for(int i = 3;i < n;i += 2){
scanf("%d%d",&a,&b);
printf("%d %d ",-b,a);
}
}
printf("\n");
}
return 0;
}``````
————————

Main idea of the topic: given n data A1, A2, A3, A4… An, find Bi so that Σ AI * Bi = 0

Problem solving ideas:

Consider a case: B1 corresponding to A1 = – B2  ， a2   Corresponding B2 = A1, then A1B1 + a2b2 = – A1B2  +  a1b2  = 0

Then, for the case where n is an even number, you only need to perform the above operation for every two a

For the case where n is an odd number, consider transforming two of the three a into one, and then into the case where n is an even number

AC Code:

``````#include<bits/stdc++.h>

using namespace std;

int main(){
int n,T;
scanf("%d",&T);

while(T --){
scanf("%d",&n);
if(n % 2 == 0){
int a,b;

for(int i = 0;i < n;i += 2){
scanf("%d%d",&a,&b);
printf("%d %d ",-b,a);
}
}
else {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);

if(a + b != 0){
printf("%d %d %d ",-c,-c,a + b);
}

else if(a + c != 0){
printf("%d %d %d ",-b,a + c,-b);
}
else{
printf("%d %d %d ",b + c,-a,-a);
}

for(int i = 3;i < n;i += 2){
scanf("%d%d",&a,&b);
printf("%d %d ",-b,a);
}
}
printf("\n");
}
return 0;
}``````