标签:type for har get closed 图片 返回 ace style
题意:
有n个员工,每个员工的薪资区间为[li , ri]
问员工薪资的中位数最大是多少。
思路:
二分答案,check()检查薪资 >= mid 的人数 >= n/2 + 1 则返回 true , 不然返回 false
1 #include<cstdio> 2 #include<string.h> 3 #include<algorithm> 4 #include<cmath> 5 #include<iostream> 6 #include<vector> 7 #include<queue> 8 #include<set> 9 #include<map> 10 #include<cctype> 11 #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) 12 #define mem(a,x) memset(a,x,sizeof(a)) 13 #define lson rt<<1,l,mid 14 #define rson rt<<1|1,mid + 1,r 15 #define P pair<int,int> 16 #define ull unsigned long long 17 using namespace std; 18 typedef long long ll; 19 const int maxn = 1e6 + 10; 20 const ll mod = 998244353; 21 const int inf = 0x3f3f3f3f; 22 const long long INF = 0x3f3f3f3f3f3f3f3f; 23 const double eps = 1e-7; 24 inline ll read() 25 { 26 ll X = 0, w = 0; char ch = 0; 27 while (!isdigit(ch)) { w |= ch == ‘-‘; ch = getchar(); } 28 while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); 29 return w ? -X : X; 30 } 31 ll n, m, k; 32 ll cnt[maxn] = {0}; 33 ll ou = 0, ji = 0; 34 vector<int>vec[maxn]; 35 36 int main() 37 { 38 n = read(), m = read(); 39 int ans = min(n, m); 40 cout << ans + 1 << endl; 41 for (int i = 0; i <= ans; ++i) 42 { 43 cout << ans - i << " " << i << endl; 44 } 45 return 0; 46 }
Salary Changing CodeForces - 1251D (二分)
标签:type for har get closed 图片 返回 ace style
原文地址:https://www.cnblogs.com/DreamACMer/p/12694247.html