首页 > 其他 > 详细

ZROI#986

时间:2019-09-15 21:30:28      阅读:121      评论:0      收藏:0      [点我收藏+]

ZROI#986

曾经\(wqy\) 在校内模拟赛给我们出过这么一道题.
但我完全没想起来怎么做,于是就只能瞎贪.
然后\(10pts\)走人了....
你考虑,假定答案是\(k\),那么一定是最大的\(k\)个和最小的\(k\)袋鼠配对.
从大到小贪心即可.
\(Code:\)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>
#define int long long
#define pb push_back

using std::queue ;
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;

template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
       while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
   return f * x ;
}

const int N = 1e6 + 100 ;

int n , v[N] , ans ;

signed main (int argc , char * argv[]) {
    n = rint () ;
    for (int i = 1 ; i <= n ; ++ i) v[i] = rint () ;
    std::sort ( v + 1 , v + n + 1 ) ;
    int cur = n , p = ( n >> 1 ) ;
    while ( true ) {
        if ( v[p] * 2 <= v[cur] ) ++ ans , -- cur ;
        if ( cur <= ( n >> 1 ) ) break ;
        -- p ; if ( ! p ) break ;
    }
    printf ("%d\n" , ans ) ;
    return 0 ;
}

ZROI#986

原文:https://www.cnblogs.com/Equinox-Flower/p/11523845.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!