目录
5047. 1序列
题目描述:
实现代码:
5048. 无线网络
题目描述:
实现代码:
二分 + 贪心
5049. 选人
题目描述:
实现代码:
数学
5047. 1序列
题目描述:
实现代码:
#include<iostream>using namespace std;int main()
{int t;cin >> t;while (t--){int a;cin >> a;for (int i = 0; i < a; i++) cout << 1 << " ";puts("");}
}
5048. 无线网络
题目描述:
实现代码:
二分 + 贪心
#include<iostream>
#include<algorithm>
using namespace std;const int N = 200010;
double x[N];
int t;
vector<double> res;// 贪
bool check(double m)
{res.clear();res.push_back(x[0] + m);for (int i = 1; i < t; i++){if (res.back() + m < x[i]){if (res.size() == 3) return false;res.push_back(x[i] + m);}}return true;
}int main()
{cin >> t;for (int i = 0; i < t; i++) cin >> x[i];sort(x, x + t);double l = 0, r = 5e8,eps = 1e-7;while (r - l > eps){double mid = (l + r) / 2;if (check(mid)) r = mid;else l = mid;}check(r);printf("%lf\n", r);while (res.size() < 3) res.push_back(0);for (int i = 0; i < 3; i++){printf("%lf ", res[i]);}return 0;
}
5049. 选人
题目描述:
实现代码:
数学
#include<iostream>using namespace std;const int N = 1010;int x[N];
int n, m ,h;int main()
{cin >> n >> m >> h;int sum = 0;for (int i = 1; i <= m; i++){cin >> x[i];sum += x[i];}if (sum < n){puts("-1");return 0;}if (n - 1 > sum - x[h]){cout << 1 << endl;return 0;}double res = 1;for (int i = 0; i < n - 1; i++){res *= (double)(sum - x[h] - i) / (sum - 1 - i);}printf("%lf", 1 - res);return 0;}