J. Parallelograms

版权声明:大家一起学习,欢迎转载,转载请注明出处。若有问题,欢迎纠正! https://blog.csdn.net/memory_qianxiao/article/details/79953238

J. Parallelograms
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

There are n sticks, the i-th of which has length ai. Alex wants to assemble from them as many parallelograms as possible simultaneously, with each stick used at most in one parallelogram. What maximal number of parallelograms is it possible to assemble?

Input

The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of sticks.

The second line contains n integers ai (1 ≤ ai ≤ 200000) — the lengths of sticks.

Output

Output a single integer — the maximal number of parallelograms that is possible to assemble.

Examples
input
Copy
4
1 2 1 2
output
Copy
1
input
Copy
12
1 3 5 7 1 3 5 7 1 3 5 7
output
Copy
2


题意:给你n个棍子,然后第二行是每个棍子的长度。问最多能够组成多少平行四边形。
题解:模拟  记录每种长度的棍子,然后如果是奇数的话,棍子数减1,因为我们只会用到偶数棍子。因为一个平行四边形是四条边。最后把每种长度的棍子数加起来/4就是答案。

#include<bits/stdc++.h>
using namespace std;
int n,a[200100],sum=0,x;
int main()
{

    cin>>n;
    for(int i=0; i<n; i++)
        cin>>x,a[x]++;
    for(int i=0; i<=200000; i++)
    {
        if(a[i]&1)
            a[i]--;
        sum+=a[i],a[i]=0;
    }
    cout<<sum/4<<endl;
    return 0;
}

阅读更多 登录后自动展开

扫码向博主提问

Memory丿浅笑

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • python
  • c++
  • 爬虫
去开通我的Chat快问
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页