F - Finding Sasuke

F - Finding Sasuke

Naruto has sneaked into the Orochimaru’s lair and is now looking for Sasuke. There are T rooms there. Every room has a door into it, each door can be described by the number n of seals on it and their integer energies a1, a2, …, an. All energies ai are nonzero and do not exceed 100 by absolute value. Also, n is even.

In order to open a door, Naruto must find such n seals with integer energies b1, b2, …, bn that the following equality holds: a1⋅b1+a2⋅b2+…+an⋅bn=0. All bi must be nonzero as well as ai are, and also must not exceed 100 by absolute value. Please find required seals for every room there.

Input
The first line contains the only integer T (1≤T≤1000) standing for the number of rooms in the Orochimaru’s lair. The other lines contain descriptions of the doors.

Each description starts with the line containing the only even integer n (2≤n≤100) denoting the number of seals.

The following line contains the space separated sequence of nonzero integers a1, a2, …, an (|ai|≤100, ai≠0) denoting the energies of seals.

Output
For each door print a space separated sequence of nonzero integers b1, b2, …, bn (|bi|≤100, bi≠0) denoting the seals that can open the door. If there are multiple valid answers, print any. It can be proven that at least one answer always exists.

Example
Input
2
2
1 100
4
1 2 3 6
Output
-100 1
1 1 1 -1
Note
For the first door Naruto can use energies [−100,1]. The required equality does indeed hold: 1⋅(−100)+100⋅1=0.

For the second door Naruto can use, for example, energies [1,1,1,−1]. The required equality also holds: 1⋅1+2⋅1+3⋅1+6⋅(−1)=0.

题意:
输入n个整数,将这n个数进行运算使其相加等于0,输出每个数进行的运算方式。

思路:
将输入的n个整数倒序输出,将其中一半输出为负即可。这道题只要弄清楚题意就很简单了。

#include"stdio.h"
int main()
{
	int t,n,m;
	int a[105];
	while(~scanf("%d",&t))
	{
		for(int j=1;j<=t;j++)
		{
			scanf("%d",&n);
			for(int i=1;i<=n;i++)
			{
				scanf("%d",&a[i]);
			}
			for(int i=n;i>n/2;i--)
			{
				printf("%d ",-a[i]);
			}
			for(int i=n/2;i>=1;i--)
			{
				printf("%d ",a[i]);
			}
			printf("\n");
		}
	}
	return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值