E. Boxers ( Codeforces Round #579 )
Posted shallow-dream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E. Boxers ( Codeforces Round #579 )相关的知识,希望对你有一定的参考价值。
There are nn boxers, the weight of the ii-th boxer is aiai. Each of them can change the weight by no more than 11 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number.
It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers‘ weights in the team are different (i.e. unique).
Write a program that for given current values ?aiai will find the maximum possible number of boxers in a team.
It is possible that after some change the weight of some boxer is 150001150001 (but no more).
The first line contains an integer nn (1≤n≤1500001≤n≤150000) — the number of boxers. The next line contains nn integers a1,a2,…,ana1,a2,…,an, where aiai (1≤ai≤1500001≤ai≤150000) is the weight of the ii-th boxer.
Print a single integer — the maximum possible number of people in a team.
4
3 2 4 1
4
6
1 1 1 4 4 4
5
In the first example, boxers should not change their weights — you can just make a team out of all of them.
In the second example, one boxer with a weight of 11 can be increased by one (get the weight of 22), one boxer with a weight of 44 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 33 and 55, respectively). Thus, you can get a team consisting of boxers with weights of 5,4,3,2,15,4,3,2,1.
#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> typedef long long ll; using namespace std; const int INT=1e6+5; #define lson rt<<1, l, m #define rson rt<<1|1, m+1, r #define read(x) scanf("%d",&x) #define lread(x) scanf("%lld",&x); #define pt(x) printf("%d\n",(x)) #define cn cin>> #define ct cout<< #define en <<endl #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++) #define input(k) for (int i = 1; i <= (int)(k); i++) cin>>a[i] ; #define mem(s,t) memset(s,t,sizeof(s)) #define re return 0; #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int a[151000]; bool vis[151000]; int main() TLE; int n; scanf("%d",&n); for(int i = 1; i <= n; ++i) scanf("%d",&a[i]); sort(a+1,a+1+n); int sum = 0; for(int i = 1; i <= n; ++i) if(!vis[a[i]-1] && a[i] != 1) vis[a[i]-1] = true; sum++;continue; if(!vis[a[i]]) vis[a[i]] = true; sum++;continue; if(!vis[a[i]+1]) vis[a[i]+1] = true; sum++;continue; cout<<sum<<endl; return 0;
以上是关于E. Boxers ( Codeforces Round #579 )的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces 785 E. Anton and Permutation(分块,树状数组)
codeforces 617 E. XOR and Favorite Number(莫队算法)
Codeforces Round #167 (Div. 1) E. Dima and Game
Codeforces 408 E. Curious Array