Educational Codeforces Round 99_E. Four Points

E. Four Points

题目链接在此!

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

题意分析:

四个点,一次操作可以将其中一个点向上下左右任意一个方向移动一个单位,问最少要多少次操作才能使得四个点组成平行于x轴和y轴的正方形。

代码:

/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           |   \_| ''\-/''  |   |
           \  .-\__  `-`  ___/-. /
          ___`. .'  /-.-\  `. . __
      ."" '<  `.___\_<|>_/___.'  >' "".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                    `=-='

*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stdio.h>
#include <map>

typedef long long ll;
const ll mod = 1e9 + 7;

using namespace std;

ll a[4];
struct Node {
    ll shortt, longg, size;
};

Node s(ll x1, ll x2, ll x3, ll x4) {
    if (x1 > x2)swap(x1, x2);
    if (x3 > x4)swap(x3, x4);
    ll shortt,longg,size;
    if(x3>x2) shortt=x3-x2;
    else{
        if(x1>x4)
            shortt=x1-x4;
        else shortt=0;
    }
   longg = max(abs(x4 - x1), abs(x2 - x3));
    size = x2 - x1 + x4 - x3;
    Node node{};
    node.longg = longg;
    node.size = size;
    node.shortt = shortt;
    return node;
}

ll calc(Node x, Node y) {
    ll result;
    if (x.longg < y.shortt) {
        result = x.size + y.size + (y.shortt - x.longg) * 2;
    } else if (x.shortt > y.longg) {
        result = x.size + y.size + (x.shortt - y.longg) * 2;
    } else
        result = x.size + y.size;
    return result;
}

int main() {
    ll t, x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> t;
    for (int i = 0; i < t; i++) {
        cin >> x1 >> y1;
        cin >> x2 >> y2;
        cin >> x3 >> y3;
        cin >> x4 >> y4;
//        Node x = s(x1, x2, x3, x4), y = s(y1, y2, y3, y4);
        ll r1 = calc(s(x1, x2, x3, x4), s(y1, y3, y2, y4)),
                r2 = calc(s(x1, x2, x3, x4), s(y1, y4, y2, y3)),
                r3 = calc(s(x1, x3, x2, x4), s(y1, y2, y3, y4)),
                r4 = calc(s(x1, x3, x2, x4), s(y1, y4, y2, y3)),
                r5 = calc(s(x1, x4, x2, x3), s(y1, y2, y3, y4)),
                r6 = calc(s(x1, x4, x2, x3), s(y1, y3, y2, y4));
        ll result = min(r1, min(r2, min(r3, min(r4, min(r5, r6)))));
        cout << result << endl;
    }
    return 0;
}
/*
皮卡丘冲鸭!
へ     /|
  /\7    ∠_/
  / │   / /
 │ Z _,< /   /`ヽ
 │     ヽ   /  〉
  Y     `  /  /
 イ  ● 、 ● ⊂⊃〈  /
 ()  へ    | \〈
  >ー 、_  ィ  │ //
  / へ   / ノ<| \\
  ヽ_ノ  (_/  │//
  7       |/
  >―r ̄ ̄`ー―_
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值