admin管理员组文章数量:1530020
There are n people who want to participate in a boat competition. The weight of the i-th participant is wi. Only teams consisting of two people can participate in this competition. As an organizer, you think that it’s fair to allow only teams with the same total weight.
So, if there are k teams (a1,b1), (a2,b2), …, (ak,bk), where ai is the weight of the first participant of the i-th team and bi is the weight of the second participant of the i-th team, then the condition a1+b1=a2+b2=⋯=ak+bk=s, where s is the total weight of each team, should be satisfied.
Your task is to choose such s that the number of teams people can create is the maximum possible. Note that each participant can be in no more than one team.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1≤t≤1000) — the number of test cases. Then t
test cases follow.
The first line of the test case contains one integer n (1≤n≤50) — the number of participants. The second line of the test case contains n integers w1,w2,…,wn (1≤wi≤n), where wi is the weight of the i
-th participant.
Output
For each test case, print one integer k: the maximum number of teams people can compose with the total weight s, if you choose s optimally.
Input
Copy
5
5
1 2 3 4 5
8
6 6 6 6 6 6 8 8
8
1 2 2 1 2 1 1 2
3
1 3 3
6
1 1 3 4 2 2
Output
Copy
2
3
4
1
2
Note
In the first test case of the example, we can reach the optimal answer for s=6. Then the first boat is used by participants 1 and 5 and the second boat is used by participants 2 and 4(indices are the same as weights).In the second test case of the example, we can reach the optimal answer for s=12
. Then first 6 participants can form 3 pairs.
In the third test case of the example, we can reach the optimal answer for s=3. The answer is 4 because we have 4 participants with weight 1 and 4 participants with weight 2.
In the fourth test case of the example, we can reach the optimal answer for s=4 or s=6.
In the fifth test case of the example, we can reach the optimal answer for s=3. Note that participant with weight 3 can’t use the boat because there is no suitable pair for him in the list.
根据样例来看,题目大意是给出一个数组,让求这个数组里有多少对的和是相等的。
因为数据比较小,所以我是直接枚举这两个数的和会是多少,然后在枚举数组,因为算了两次,所以,最后要除以2
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
int aa[1010],bb[1010];
int main()
{
int n,x;
cin>>n;
while(cin>>n)
{
int res=0;
memset(aa,0,sizeof aa);
memset(aa,0,sizeof aa);
for(int i=0;i<n;i++)
{
cin>>x;
aa[x]++;
}
for(int i=0;i<=100;i++)
{ //枚举和
int ll=0;
memcpy(bb,aa,sizeof aa);
for(int j=0;j<=100;j++)
{
if(i-j>=0)
{
ll+=min(aa[j],aa[i-j]);
bb[j]-=min(aa[j],aa[i-j]);
bb[i-j]-=min(aa[j],aa[i-j]);
}
}
res=max(res,ll/2);
}
cout<<res<<endl;
}
return 0;
}
本文标签: Boatscompetition
版权声明:本文标题:C. Boats Competition 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726692890a1080895.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论