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;
                        }
                }
        }
}
View Code

C

 

posted @ 2018-04-17 23:44  Aragaki  阅读(232)  评论(0编辑  收藏  举报