⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p1788.cpp

📁 大概POJ上50道比较难的题的代码
💻 CPP
字号:
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 100001;
struct point{
       int x,y;
};
point a[MAXN];
bool cmpx(point a,point b){
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}
bool cmpy(point a,point b){
    return a.y < b.y || (a.y == b.y && a.x < b.x);
}
int main(){
    int p;
    while(cin >> p && p){
        int ans(0);
        for(int i = 0;i < p;++i) scanf("%d%d",&a[i].x,&a[i].y);
        sort(a,a+p,cmpx);
        int i;
        i = 1;
        while(i < p){
            while(a[i].x == a[i-1].x && i < p){
                if(i % 2) ans += abs(a[i].y - a[i-1].y);
                ++i;
            }
            ++i;
        }
        sort(a,a+p,cmpy);
        i = 1;
        while(i < p){
            while(a[i].y == a[i-1].y && i < p){
                if(i % 2) ans += abs(a[i].x - a[i-1].x);
                ++i;
            }
            ++i;
        }
        printf("The length of the fence will be %d units.\n",ans);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -