zoukankan      html  css  js  c++  java
  • cf 20190307 Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)

    B. Mike and Children
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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) (1i,jn1≤i,j≤n ) such that iji≠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.

    Input

    The first line contains one integer nn (2n10002≤n≤1000 ) — the number of sweets Mike has.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1051≤ai≤105 ) — the sizes of the sweets. It is guaranteed that all integers are distinct.

    Output

    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.

    Examples
    Input
    Copy
    8
    1 8 3 11 4 9 2 7
    
    Output
    Copy
    3
    
    Input
    Copy
    7
    3 1 7 11 9 2 12
    
    Output
    Copy
    2
    
    Note

    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
    ",ans);
    	return 0;
    }
    

      

  • 相关阅读:
    asp.net 发送邮件
    效控制C#中label输出文字的长度,自动换行
    无法连接到WMI 提供程序 请注意,你只能使用SQL Server 配置管理器来管理SQL Server 2005服务器。找不到指定的模块。[0x8007007e]
    查询区分大小写
    ASP.NET母版页引用外部css和js文件的写法
    VS2008 Debugging Breakpoint 补丁
    firefox下获得焦点
    IE打开出现windows找不到文件'(null)'解决方法Vinzipblog文之巴博客
    邪恶的web上下键焦点移动
    jQuery对下拉框Select操作总结
  • 原文地址:https://www.cnblogs.com/EchoZQN/p/10492143.html
Copyright © 2011-2022 走看看