HDOJ 2555 人人都能参加第30届校田径运动会了

239 篇文章 0 订阅

HDACM 2555

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        Point1 points[] = new Point1[m];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            points[i] = new Point1(x,y);
        }
        Rectangle rects[] = new Rectangle[n];
        for (int i = 0; i < n; i++) {
            int x1 = sc.nextInt(); 
            int y1 = sc.nextInt(); 
            int x2 = sc.nextInt(); 
            int y2 = sc.nextInt(); 
            rects[i] = new Rectangle(new Point1(x1, y1), new Point1(x2, y2));
        }
        int lens[] = new int[m];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (rects[j].isInner(points[i])) {
                    lens[i] = rects[j].perime;
                    break;
                }
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = i+1; j < m; j++) {
                if (lens[i]<lens[j]) {
                    int t = lens[i];
                    lens[i] = lens[j];
                    lens[j] = t;
                }
            }
        }
        for (int i = 0; i < lens.length; i++) {
            System.out.println(lens[i]);
        }
        sc.close();
    }
}

class Point1{
    int x;
    int y;
    public Point1() {
    }
    public Point1(int x, int y) {
        super();
        this.x = x;
        this.y = y;
    }
}
class Rectangle{
    Point1 p1;
    Point1 p2;
    int perime;
    public Rectangle() {
    }
    public Rectangle(Point1 p1, Point1 p2) {
        super();
        this.p1 = p1;
        this.p2 = p2;
        perime = perimeter();
    }
    public int perimeter(){
        return (Math.abs(p2.x-p1.x)+Math.abs(p2.y-p1.y))*2;
    }
    public boolean isInner(Point1 p){
        if (p.x<=p2.x&&p.x>=p1.x&&p.y<=p2.y&&p.y>=p1.y) {
            return true;
        }
        return false;
    }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值