cf 20190307 Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)
2 seconds
256 megabytes
standard input
standard output
Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.
Mike has nn sweets with sizes a1,a2,…,ana1,a2,…,an . All his sweets have different sizes. That is, there is no such pair (i,j)(i,j) (1≤i,j≤n1≤i,j≤n ) such that i≠ji≠j and ai=ajai=aj .
Since Mike has taught for many years, he knows that if he gives two sweets with sizes aiai and ajaj to one child and akak and apap to another, where (ai+aj)≠(ak+ap)(ai+aj)≠(ak+ap) , then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset.
Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can.
Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset.
The first line contains one integer nn (2≤n≤10002≤n≤1000 ) — the number of sweets Mike has.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1051≤ai≤105 ) — the sizes of the sweets. It is guaranteed that all integers are distinct.
Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset.
8
1 8 3 11 4 9 2 7
3
7
3 1 7 11 9 2 12
2
In the first example, Mike can give 9+2=119+2=11 to one child, 8+3=118+3=11 to another one, and 7+4=117+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution.
In the second example, Mike can give 3+9=123+9=12 to one child and 1+111+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
这个题目,其实不太难,但是我自己还是没有独立解决,水平严重有待提升,这个呢要注意n个数都互不相等的,所以这说明要是求出相等的,则肯定不会用到同一个数 (a[i]+a[j]==a[i]+a[k]不可能成立)
知道这个我就会写了,就直接二重循环即可
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1300;
const int inf=2e5+10;
int p[inf];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,a[maxn];
ll ans=0;
memset(p, 0, sizeof(p));
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
{
for (int j = i+1; j <= n; j++)
{
p[a[i] + a[j]]++;
ans=max(1ll*p[a[i]+a[j]],ans);
} }
printf("%d\n",ans);
return 0;
}
cf 20190307 Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)的更多相关文章
- Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)
A. Technogoblet of Fire 题意:n个人分别属于m个不同的学校 每个学校的最强者能够选中 黑客要使 k个他选中的可以稳被选 所以就为这k个人伪造学校 问最小需要伪造多少个 思路:记 ...
- Codeforces Round #543 (Div. 1, based on Technocup 2019 Final Round) 题解
题面戳这里 A. Diana and Liana 首先如果s>ks>ks>k一定无解,特判一下.那么我们考虑找恰好满足满足题目中的要求的区间[l,r][l,r][l,r],那么需要要 ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path
http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)
https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】
任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup
The last stage of Football World Cup is played using the play-off system. There are n teams left in ...
随机推荐
- 菜鸟入门【ASP.NET Core】14:MVC开发:UI、 EF + Identity实现、注册实现、登陆实现
前言 之前我们进行了MVC的web页面的Cookie-based认证实现,接下来的开发我们要基于之前的MvcCookieAuthSample项目做修改. MvcCookieAuthSample项目地址 ...
- js中const,var,let区别(转载)
js中const,var,let区别 来源:https://www.cnblogs.com/zzsdream/p/6372729.html 今天第一次遇到const定义的变量,查阅了相关资料整理了这篇 ...
- 【Java每日一题】20170316
20170315问题解析请点击今日问题下方的“[Java每日一题]20170316”查看(问题解析在公众号首发,公众号ID:weknow619) package Mar2017; public cla ...
- P、NP、NPC、NP-Hard问题到底是何方神圣?
最近在做一个求解有向图中回路的问题,老师说求解图中全部回路是一个NP难问题.突然想到P.NP.NPC.NP-hard的描述一致不是很清楚,所以又学习了一下. 在解释这四个概念之前,我们需要先知道两个问 ...
- sping框架纯注解配置
1.相关注解 ①@Configuration注解-->添加了该注解在类上,就表明该类是spring的配置类.该类的作用是用来替代原来的XML配置文件的. 通过配置类创建容器时,需要使用Annot ...
- 【Java深入研究】10、红黑树
一.红黑树介绍 红黑树是二叉查找树,红黑树的时间复杂度为: O(lgn) 红黑树的特性:(1)每个节点或者是黑色,或者是红色.(2)根节点是黑色.(3)每个叶子节点(NIL)是黑色. [注意:这里叶子 ...
- 带你使用JS-SDK自定义微信分享效果
前言 想必各位在写wap端时都遇到过这样的场景吧 ----自定义分享标题.图片.描述 接下来小编给大家讲解下分享相关操作 预期效果 原始的分享效果: 使用微信JS-SDK的分享效果: 可以看出缩略图, ...
- 前端入门2-HTML标签
本篇文章已授权微信公众号 dasu_Android(大苏)独家发布 声明 本系列文章内容全部梳理自以下四个来源: <HTML5权威指南> <JavaScript权威指南> MD ...
- mac svn的使用
一.概述 在windows下,我们常常用TortoiseSVN管理svn代码.在mac下,自带svn客户端和服务器端功能. 二.服务端:创建代码仓库,用来存储客户端所上传的代码 (1)创建svn代码存 ...
- JS之函数实际参数转换成数组的方法[].slice.call(arguments)
实际参数在函数中我们可以使用 arguments 对象获得 (注:形参可通过 arguments.callee 获得),虽然 arguments 对象与数组形似,但仍不是真正意义上的数组. 我们可以通 ...