Gym 101612 Problem I. Intelligence in Perpendicularia

Gym 101612 Problem I. Intelligence in Perpendicularia_第1张图片
思路:
点绘制出的多边形,且直线只能平行x轴或者y轴。
要求看不见的边有多长。

思路:
只需要算出周长,减去外周长就好了。

#include
#include
#include
#include
#include

typedef long long ll;
using namespace std;
const int maxn = 1e3 + 7;

struct Node {
     
    int x,y;
}a[maxn];

int main() {
     
    freopen("intel.in","r",stdin);
    freopen("intel.out","w",stdout);

    int n;scanf("%d",&n);
    for(int i = 1;i <= n;i++) {
     
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    
    ll ans = 0;
    int mxX = 0,mxY = 0,miX = 1e9,miY = 1e9;
    a[n + 1] = a[1];
    for(int i = 2;i <= n + 1;i++) {
     
        if(a[i - 1].x == a[i].x) {
     
            int num = abs(a[i].y - a[i - 1].y);
            ans += num;
        } else {
     
            int num = abs(a[i].x - a[i - 1].x);
            ans += num;
        }
        mxX = max(mxX,a[i].x);
        miX = min(miX,a[i].x);
        mxY = max(mxY,a[i].y);
        miY = min(miY,a[i].y);
    }
    
    
    ans -= (mxX - miX) * 2 + (mxY - miY) * 2;
    printf("%lld\n",ans);
    return 0;
}

你可能感兴趣的:(#,gym)