码迷,mamicode.com
首页 > 其他好文 > 详细

ACR095 删一个求中位数 贪心求最大组合数 行列变换模拟(搜索)

时间:2018-04-18 00:58:43      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:1.0   ide   scanf   display   class   eof   unsigned   def   alt   

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

 

ACR095 删一个求中位数 贪心求最大组合数 行列变换模拟(搜索)

标签:1.0   ide   scanf   display   class   eof   unsigned   def   alt   

原文地址:https://www.cnblogs.com/Aragaki/p/8870878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!