C. Photo of The Sky

31 篇文章 0 订阅
11 篇文章 0 订阅
  • 题目链接:http://codeforces.com/contest/1013/problem/C
  • 题意:给你2*n 个整数,要求你把这2*n个数分为两组,一组为x坐标,一组为y坐标,每组n个数。任你选一种组合方式,让其组成n个点,使得包含所有xy坐标表示的点的矩形(边与坐标轴平行)的最小面积。输出最小面积
  • 思路:包含两种情况:
    • 一 :最大值和最小值在同一组中:那么一条边就确定为max(x)-min(x),接着求另一条边。要求 这条边长度最小。由已知,每组有n个数,由于第一条边已经确定,其余各点都在该边范围内。所以只要求出另一组中的max(y)-min(y)即可。将2*n个数sort以后,只需要找出最小的连续n个数的max(y)-min(y)就行,答案即为(max(x)-min(x))* min(max(y)-min(y))
    • 二:最大值和最小值不在同一组中:假设最小值在X组中,最大值在Y组中。因为X组的大小为n,所以X组中的最大值max(x) >= a[n];又因为Y组的大小为n,所以Y组中的最小值min(y) <= a[n+1]。所以 (max(x) - min(x)) * (max(y) - min(y)) >= (a[n]-a[1])(a[2*n]-a[n+1])。因此面积的最小值等于(a[n]-a[1])(a[2*n]-a[n+1])

#include <bits/stdc++.h>
#define pi acos(-1)
#define fastcin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;       // 不能加负号!!!
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;//4e18 ~= 2^62
const int maxn =100000 + 10;
const LL mod = 1e9+7;

LL a[maxn*2];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=1; i<=2*n; i++){
        scanf("%I64d", &a[i]);
    }
    sort(a+1, a+1+2*n);
    LL ans = 0;
    ans = (a[n]-a[1])*(a[2*n]-a[n+1]);
    LL tmp = 0;
    for(int i=2; i<=n; i++){
        tmp = a[i+n-1] - a[i];
        ans = min(ans, tmp*(a[2*n]-a[1]));
    }
    //printf("%I64d %I64d %I64d %I64d\n", a[n], a[1], a[2*n], a[n+1]);
    cout << ans << endl;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值