ccfcsp202303-1 田地丈量

 

试题编号:202303-1
试题名称:田地丈量
时间限制:1.0s
内存限制:512.0MB
问题描述:

问题描述

西西艾弗岛上散落着 𝑛 块田地。每块田地可视为平面直角坐标系下的一块矩形区域,由左下角坐标 (𝑥1,𝑦1) 和右上角坐标 (𝑥2,𝑦2) 唯一确定,且满足 𝑥1<𝑥2、𝑦1<𝑦2。这 𝑛 块田地中,任意两块的交集面积均为 0,仅边界处可能有所重叠。

最近,顿顿想要在南山脚下开垦出一块面积为 𝑎×𝑏 矩形田地,其左下角坐标为 (0,0)、右上角坐标为 (𝑎,𝑏)。试计算顿顿选定区域内已经存在的田地面积。

输入格式

从标准输入读入数据。

输入共 𝑛+1 行。

输入的第一行包含空格分隔的三个正整数 𝑛、𝑎 和 𝑏,分别表示西西艾弗岛上田地块数和顿顿选定区域的右上角坐标。

接下来 𝑛 行,每行包含空格分隔的四个整数 𝑥1、𝑦1、𝑥2 和 𝑦2,表示一块田地的位置。

输出格式

输出到标准输出。

输出一个整数,表示顿顿选定区域内的田地面积。

样例输入

4 10 10
0 0 5 5
5 -2 15 3
8 8 15 15
-2 10 3 15

样例输出

44

子任务

全部的测试数据满足 𝑛≤100,且所有输入坐标的绝对值均不超过 104。

import java.io.*;

public class Main {
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static QuickInput in = new QuickInput();

    public static int jiao(int x1,int x2,int y1,int y2){
        int tou=Math.max(x1,y1);
        int wei=Math.min(x2,y2);
        if(tou<wei){
            return wei-tou;
        }
        return 0;
    }
    public static int get(int i,int[][] arr,int a,int b){
        int c=jiao(arr[i][0],arr[i][2],0,a);
        int k=jiao(arr[i][1],arr[i][3],0,b);
        return c*k;
    }

    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int a=in.nextInt();
        int b=in.nextInt();
        int[][] arr=new int[n][4];
        int sum=0;
        for(int i=0;i<n;i++){
            arr[i][0]=in.nextInt();
            arr[i][1]=in.nextInt();
            arr[i][2]=in.nextInt();
            arr[i][3]=in.nextInt();
            sum+=get(i,arr,a,b);
        }
        out.println(sum);

        out.flush();
    }

    static class QuickInput {
        StreamTokenizer input = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        int nextInt() throws IOException {
            input.nextToken();
            return (int) input.nval;
        }


    }
}

  • 15
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值