ACR095 删一个求中位数 贪心求最大组合数 行列变换模拟(搜索)
Posted Aragaki
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ACR095 删一个求中位数 贪心求最大组合数 行列变换模拟(搜索)相关的知识,希望对你有一定的参考价值。
A
B
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int num[100005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); } sort(num + 1, num + 1 + n); if (n == 2) { cout << num[2] << " " << num[1] << endl; return 0; } else { int minn = 1e9; cout << num[n] << " "; int now = num[n] / 2; int now2 = num[n] / 2 + num[n] % 2; for (int i = 1; i <= n - 1; i++) { minn = min(minn, min(abs(num[i] - now), abs(num[i] - now2))); } for (int i = 1; i <= n - 1; i++) { if (min(abs(num[i] - now), abs(num[i] - now2)) == minn) { cout << num[i] << endl; return 0; } } } }
C
以上是关于ACR095 删一个求中位数 贪心求最大组合数 行列变换模拟(搜索)的主要内容,如果未能解决你的问题,请参考以下文章