codeforces 1283 C 贪心
贪心瞎搞
题意:给了n个数,对于任意i,ai都可以变成ai+1,ai-1,ai三个位置。问进行任意次操作,最少和最多可以覆盖多少个数。
思路:排序a从小到大,对于每一个ai,优先选择左面的(ai-1)没有选择的位置,最后被标记的位置数列即使最多的个数。
优先选择最右面的(ai+1)选择了的位置,如果都没选择,则选择ai+1,然后统计覆盖的数列寄给最少的个数。
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <map> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <set> #include <vector> // #include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sp ' ' #define endl '\n' #define inf 0x3f3f3f3f; #define FOR(i,a,b) for( int i = a;i <= b;++i) #define bug cout<<"--------------"<<endl #define P pair<int, int> #define fi first #define se second #define pb(x) push_back(x) #define ppb() pop_back() #define mp(a,b) make_pair(a,b) #define ms(v,x) memset(v,x,sizeof(v)) #define rep(i,a,b) for(int i=a;i<=b;i++) #define repd(i,a,b) for(int i=a;i>=b;i--) #define sca3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c)) #define sca2(a,b) scanf("%d %d",&(a),&(b)) #define sca(a) scanf("%d",&(a)); #define sca3ll(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c)) #define sca2ll(a,b) scanf("%lld %lld",&(a),&(b)) #define scall(a) scanf("%lld",&(a)); using namespace std; typedef long long ll; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll powmod(ll a, ll b, ll mod){ll sum = 1;while (b) {if (b & 1) {sum = (sum * a) % mod;b--;}b /= 2;a = a * a % mod;}return sum;} const double Pi = acos(-1.0); const double epsilon = Pi/180.0; const int maxn = 2e5+10; int n; int a[maxn]; int vis[maxn]; int d[3] = {-1,0,1}; int main() { //freopen("input.txt", "r", stdin); cin>>n; rep(i,1,n) cin>>a[i]; sort(a+1,a+1+n); queue<pair<int,int> >que; rep(i,1,n){ rep(j,0,2){ int now = a[i]+d[j]; if(vis[now] == 0){ vis[now]=1; break; } } } int ansmax = 0; rep(i,0,n+1){ if(vis[i] == 1){ ansmax++; } } memset(vis,0,sizeof(vis)); rep(i,1,n){ int flag = 0; repd(j,2,0){ int now = a[i]+d[j]; if(vis[now] == 1){ flag = 1; break; } } if(flag == 0){ vis[a[i]+1]=1; } } int ansmin = 0; rep(i,0,n+1){ if(vis[i] == 1){ ansmin++; } } cout<<ansmin<<sp<<ansmax<<endl; }