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 ...
随机推荐
- JVM运行时数据区内容简述
JVM运行时数据区分为五个部分:程序计数器.虚拟机栈.本地方法栈.堆.方法区.如下图所示,五部分其中又分为线程共享区域和线程私有区域,下面将分别介绍每一部分. 1. PC程序计数器 程序计数器是一块较 ...
- markdown基础入门
一.标题 语法:# 文字 注意:1个#号代表标题1,两个代表标题2,依次类推 # 标题1 ## 标题2 ### 标题3 #### 标题4 ##### 标题5 ###### 标题6 二.加粗,斜体 语法 ...
- Spring 与 SpringMVC (或许不完整)
一.什么是Spring Spring是一个开源的控制反转和面向切面(AOP)的容器框架.它的主要目的是使现有技术更加易用,推荐编码最佳实现,从而简化企业的开发. 提:使用Spring的好处有以下几项: ...
- git入门 多人协作
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git remote: $ git r ...
- laravel框架详解
一.基础篇 1.概念 Laravel是一个有着美好前景的年轻框架,它的社区充满着活力,同时提供了完整而清晰的文档,而且为快速.安全地开发现代应用提供了必要的功能.2011年,Taylor Otwell ...
- git pull遇到错误:error: Your local changes to the following files would be overwritten by merge:
方法1:如果你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来) git stash git pull origin master git sta ...
- JS之汉字与Unicode码的相互转化
有时候,我们在给后端传递变量的的值中有汉字,可能由于编码的原因,传递到后端后变为乱码了.所以有时候为了省事或者其它特殊要求的时候,会把传递的汉字转换成Unicode编码后再进行传递. 当然汉字转换成u ...
- Javascript URI 解析介绍
URI 在维基百科中对于URI的解释是这样子的: 在计算机术语中,统一资源标识符(Uniform Resource Identifier,或URI)是一个用于标识某一互联网资源名称的字符串. 该种标识 ...
- 2018-10-17 Chrome插件实现GitHub代码翻译v0.0.3
续前文浏览器插件实现GitHub代码翻译原型演示, 通过调用浏览器插件-离线英汉词典的批量查词接口, 实现了源码的初步命名直译. 源码库仍在: program-in-chinese/webextens ...
- js替换字符中的斜杠反斜杠
var reg=/\\|\//g; var a="a\a\\a/b" alert(a.replace(reg,"-"));