本文共 1528 字,大约阅读时间需要 5 分钟。
曾经\(wqy\) 在校内模拟赛给我们出过这么一道题.
#include #include #include #include #include #include #include #include #include #include #include #include #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 #define int long long#define pb push_backusing 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 ;}
转载于:https://www.cnblogs.com/Equinox-Flower/p/11523845.html