Boats Competition 赛艇

来源codeforses #1399c
链接: [link](链接: link.

贪心,双指针

题面

time limit per test 2 seconds
memory limit per test 256 megabytes

There are n people who want to participate in a boat compettion. The weight of the i-th partcipant is u; . Only teams consisting of twopeople can participate in this competition.As an organizer , you think that its fair to allow only teams with the same total weight
有许多人想参加一艘船的比赛。第一批的重量是u;只有由两人组成的队伍才能参加这场比赛。作为组织者,你认为只允许总重量相同的队伍参加是公平的。

So,if there are ke teams(a,b).(ag,b )… .(QR O ). where a; is the weight of the first participant of the i-th team and by is the weightof the second participant of the i-th team, then the condition a +b =+b=…=aR +b = s, where s is the total weight ofeach team, should be satisfied.
所以,如果有KE队(a,b).(AG,b)…(Qr O)其中a;是第一组的第一名参与者的权重,by是第一组的第二名参与者的权重,则条件a+b=+b=…。=ar+b=s,其中s是队伍的总重量,应该满足。

Your task is to choose such s that the number of teams people can create is the maximum possible.Note that each paricipant can be inno 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.
输入的第一行包含一个整数t(1<t<1000)–测试用例的数量。然后是测试用例。

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 containsn integers wu1, 2,. . .,wn (1≤wi≤n), where w is the weight of the i-th participant.
测试用例的第一行包含一个整数n(1<n<50),一是参与者的数目。测试用例的第二行包含n个整数wu 1,2,。。,w(1≤wi≤n),其中w是第一参与者的权重.

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 soptimally.
对于每个测试用例,打印一个整数k:如果您选择最优的话,人们可以组合的团队的最大数量与总权重为s。

选取一个重量k使重量和等于k的两人小组数量最多,输出最多组数

两两分组等于某个值可以使用双指针

而k的取值可以二分(每个人重量在1-u,u<50),
也可从双指针序列中取待处理区间的首尾

最后贪心更新最大组数

main()
{int n;//an liint m;//ge shucin >> n;int a[55];while (n--){cin >> m;for (int i = 0; i < m; ++i)cin >> a[i];sort(a, a + m);int max=0;for(char i=0;i<m;++i)for (char j = m - 1; j > i; --j){char he=i+1, la=j-1;char num = 1;int sum = a[i] + a[j];while (he < la){if ((a[he] + a[la]) == sum){++num;++he, --la;}else if (a[he] + a[la] < sum)++he;else--la;}max = max > num ? max : num;}cout << max << endl;}return 0;
}

cf——Boats Competition 赛艇相关推荐

  1. Codeforces Round #661-C Boats Competition

    题目描述: 给出每个人的质量,要求两人一组分组,每组两人的重量和与其他组的重量和相等,求最多能分多少组. 输入描述: 第1行:t(1 \(\leq\) t \(\leq\) 1000).表示测试的个数 ...

  2. 题解 CF1399C 【Boats Competition】

    题目描述: 给出每个人的质量,要求两人一组分组,每组两人的重量和与其他组的重量和相等,求最多能分多少组. 输入描述: 第1行:t(1 \(\leq\) t \(\leq\) 1000).表示测试的个数 ...

  3. Codeforces Round #661 (Div. 3)题解

    目录 A.Remove Smallest(模拟) B.Gifts Fixing(模拟) C.Boats Competition(暴力枚举) D.Binary String To Subsequence ...

  4. Codeforces Round #661 (Div. 3)

    A - Remove Smallest 排个序,如果相邻的数大于一就不满足题意 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) ...

  5. TC(SRM)和CF入门教程for ACMer[转载]

    一.TC基本介绍TC的网址www.topcoder.com/tc,我们一般提到TC的时候是特指其中的Single Round Match(SRM).SRM的规则总结起来就是一句话:75分钟做完3道难度 ...

  6. TC(SRM)和CF入门教程for ACMer

    一.TC基本介绍 TC的网址www.topcoder.com/tc,我们一般提到TC的时候是特指其中的Single Round Match(SRM). SRM的规则总结起来就是一句话:75分钟做完3道 ...

  7. hiho 1015 KMP算法 CF 625 B. War of the Corporations

    #1015 : KMP算法 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在 ...

  8. 『参考』.net CF组件编程(4)——为自定义组件添加工具箱图标!

    前言: 在前三篇的文章中,和大家一起创建了一个用于TCP连接检测的小组件,如果你记不得了,可以通过以下链接去回顾一下: 『参考』.net CF组件编程(1)--基础之后 『参考』.net CF组件编程 ...

  9. 2009 Competition Highlights by ICPC Live

    2009 Competition Highlights by ICPC Live Links:http://www.youtube.com/watch?v=n0oZRcAz6w0 转载于:https: ...

最新文章

  1. Tornado写简易服务器
  2. 分享Kali Linux 2016.2第43周镜像
  3. Spring MVC 中的 forward 和 redirect
  4. python学习笔记(12)--程序设计方法学
  5. java j2se1.5_用J2SE1.5建立多任务的Java应用程序...
  6. qiankun 微前端_qiankun 微前端应用实践与部署(二)
  7. UE4 在游戏中使用Slate
  8. 批量获取ip运营商_关于获取运营商的IP地址
  9. Redis 存储机制
  10. Pycharm整体缩进
  11. 快速获取网站媒体资源方法
  12. Django下进行urlencode编码,可以编码中文参数的代码
  13. Gitee如何上传整个项目文件夹
  14. 读透《阿里巴巴数据中台实践》,其到底有什么高明之处?
  15. U3D_Shader编程(第二篇:基础夯实篇)
  16. 【转】小生我怕怕工具包[2010.06.17](转自52破解论坛)
  17. 中关村2019逆向 Reverse lebel:控制流平坦化 / python字节码分析
  18. 51单片机学习笔记之新建工程、点亮一盏小灯
  19. [004]爬虫系列 | 中文编码问题
  20. 第十六届智能车稳压模块设计——LOD与DCDC的使用对比

热门文章

  1. 王者空白重复名称-安卓版
  2. 怎么才能高效的打开dwg文件呢?CAD小白有什么简单的方法?
  3. yum指定镜像源安装mysql
  4. Revit二次开发之轴网标注
  5. 幼儿园认识颜色计算机游戏,【幼儿园认识颜色教案】小班公开课认识颜色_幼儿园关于颜色的教案_亲亲宝贝网...
  6. 网路钓鱼仍是违反公司的有效方法
  7. 微信发照片怎么在服务器上删除,为什么微信里面有的照片,相册里面没有,怎么删除...-卓优商学问答...
  8. linux获取token教程,一起聊-聊token认证
  9. [附源码]Python计算机毕业设计蛋糕店会员管理系统Django(程序+LW)
  10. js正则验证手机号,支持移动、电信、联通