201409-2 画图(Java 100)

  • 问题链接画图

  • 问题分析:模拟法解决。

  • 程序说明:n表示矩形个数;map数组记录坐标轴情况,此单位为true,则计算面积。

  • 程序代码

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Reader {
    static StringTokenizer token =new StringTokenizer("");
    static BufferedReader  reader   =new BufferedReader (new InputStreamReader(System.in)) ;
    static String nextLine() throws IOException {
        return reader.readLine() ;
    }
    static  String next() throws IOException {
        while(!token.hasMoreTokens()) {
            token =new StringTokenizer(reader.readLine()) ;
        }
        return token.nextToken() ;
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next()) ;
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble(next()) ;
    }

}

public class Main {

	public static void main(String[] args) throws IOException {
		int n = Reader.nextInt();
		boolean[][] map = new boolean[100][100];//false
		int res=0;
		for(int i=0;i<n;i++) {
			int x1=Reader.nextInt();
			int y1=Reader.nextInt();
			int x2=Reader.nextInt();
			int y2=Reader.nextInt();
			for(int p=y1;p<y2;p++) {
				for(int q=x1;q<x2;q++) {//借鉴物理中时间轴和时间的概念,0即表示0-1这里单位面积
					if(map[p][q]!=true) {
					map[p][q]=true;
					res++;
					}
				}
			}
		}
		System.out.print(res);
	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值