组队赛1——I——Intelligence in Perpendicularia

Problem I. Intelligence in Perpendicularia
Input file: intel.in Time limit: 3 seconds
Output file: intel.out Memory limit: 512 megabytes
There are only two directions in Perpendicularia: vertical and horizontal. Perpendicularia government
are going to build a new secret service facility. They have some proposed facility plans and want to
calculate total secured perimeter for each of them.
The total secured perimeter is calculated as the total length of the facility walls invisible for the
perpendicularly-looking outside observer. The figure below shows one of the proposed plans and
corresponding secured perimeter.
这里写图片描述

Write a program that calculates the total secured perimeter for the given plan of the secret service facility.
Input
The plan of the secret service facility is specified as a polygon.
The first line of the input contains one integer n — the number of vertices of the polygon (4 ≤ n ≤ 1000).
Each of the following n lines contains two integers xi and yi – the coordinates of the i-th vertex
(−106 ≤ xi
, yi ≤ 106
). Vertices are listed in the consecutive order.
All polygon vertices are distinct and none of them lie at the polygon’s edge. All polygon edges are either
vertical (xi = xi+1) or horizontal (yi = yi+1) and none of them intersect each other.
Output
Output a single integer — the total secured perimeter of the secret service facility.
Example
这里写图片描述

题目大意:求四个面垂直看下去的都看不到的长度总和
这个题太水了,但是逼哥和我都读不懂英语…..然后我就信了逼哥的邪,什么求射线穿插多边形,交点大于四啊什么的,三个小时也写不出来……以后得多看几遍题目,不能轻易相信逼哥

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
struct Node{
    int x,y;
}node[1111];
bool cmpx1(Node a, Node b){
    return a.x < b.x ||(a.x == b.x && a.y < b.y);
}
bool cmpy(Node a, Node b){
    return a.y < b.y ||(a.y == b.y && a.x < b.x);
}
int main(){
    int n;
    while(~scanf("%d", &n)){
        for(int i=1;i<=n; i++){
            scanf("%d%d", &node[i].x, &node[i].y);
        }
        sort(node+1, node+1+n, cmpx1);
        int num=0;
        int sum=0;
        for(int i=1;i<n;i+=2){  //第一遍
            sum += node[i+1].y-node[i].y;
        }
        int num1=node[1].x,num2 = node[n].x;
        sort(node+1, node+1+n, cmpy);
        for(int i=1;i<n;i+=2){  //第一遍
            sum += node[i+1].x-node[i].x;
        }
        int num3=node[1].y, num4=node[n].y;
        num= num2 - num1 + num4 - num3;
        sum -= 2*num;
        printf("%d\n",sum);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值