Counting Squares_hdu_1264(矩阵).java
Counting Squares
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1086 Accepted Submission(s): 540
5 8 7 10
specifies the rectangle who's corners are(5,8),(7,8),(7,10),(5,10).
If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once.
6 9 7 8
6 8 8 11
-1 -1 -1 -1
0 0 100 100
50 75 12 90
39 42 57 73
-2 -2 -2 -2
10000
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
boolean ss=false;
while(true){
boolean vis[][]=new boolean[101][101];
int a=input.nextInt();
int b=input.nextInt();
int c=input.nextInt();
int d=input.nextInt();
if(a==-2&&b==-2&&c==-2&&d==-2){
break;
}
boolean ok=false;
int sum=0;
while(!(a==-1&&b==-1&&c==-1&&d==-1)){
for(int i=Math.min(a, c)+1;i<=Math.max(a, c)&&!ok;i++){
for(int j=Math.min(b, d)+1;j<=Math.max(b, d);j++){
if(!vis[i][j]){
sum++;
vis[i][j]=true;
}
}
}
if(sum==10000)
ok=true;
a=input.nextInt();
b=input.nextInt();
c=input.nextInt();
d=input.nextInt();
if(a==-2&&b==-2&&c==-2&&d==-2){
ss=true;
break;
}
}
System.out.println(sum);
if(ss)
break;
}
}
}Counting Squares_hdu_1264(矩阵).java的更多相关文章
- 螺旋矩阵 java实现(待消化)
import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/4 17:13 * @description ...
- [剑指Offer]29-顺时针打印矩阵-Java
题目链接 https://www.nowcoder.com/practice/9b4c81a02cd34f76be2659fa0d54342a?tpId=13&tqId=11172&t ...
- LeetCode 1253. 重构 2 行二进制矩阵 - Java - 统计
题目链接:https://leetcode-cn.com/contest/weekly-contest-162/problems/reconstruct-a-2-row-binary-matrix/ ...
- 19.顺时针打印矩阵 Java
题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数 ...
- 魔术矩阵Java代码
//该魔术矩阵默认从右上角45度递增 //@漫流——595128841在qq点com //import java.util.Arrays; //用于打印API函数 public class 魔方矩阵 ...
- 剑指Offer:面试题20——顺时针打印矩阵(java实现)
题目描述: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数 字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1, ...
- leetcode 74 搜索二维矩阵 java
题目: 编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值.该矩阵具有如下特性: 每行中的整数从左到右按升序排列. 每行的第一个整数大于前一行的最后一个整数. 示例 1: 输入: mat ...
- LeetCode--054--区螺旋矩阵(java)
给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素. 示例 1: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ...
- leetcode.矩阵.766托普里茨矩阵-Java
1. 具体题目 如果一个矩阵的每一方向由左上到右下的对角线上具有相同元素,那么这个矩阵是托普利茨矩阵.给定一个 M x N 的矩阵,当且仅当它是托普利茨矩阵时返回 True. 示例 1: 输入: ma ...
随机推荐
- [React Testing] Reusing test boilerplate
Setting up a shallow renderer for each test can be redundant, especially when trying to write simila ...
- Netmon: A light-weight network monitor for Windows
Netmon is a light-weight network monitor that works on Windows operating systems. It provides differ ...
- mongo 初始配置
连接mongo 时 在window的可视化工具 有时会出现这种无法找到表的情况 那么我们所需要的是什么?? 用客户端的命令行 查看是否能够真正连接成功 下载mongo window 并安装 这个网 ...
- pd的django To Do List教程-----3:模板的建立
---恢复内容开始--- 1:在app下建立static文件夹并且放入bootstrap文件包以及一个写好的css文件style.css.文件目录如下: style.css代码: .form-cont ...
- c# 交换两个变量
使用临时变量: 有人会问只使用两个变量交换,怎么办? 不实用临时变量: 第一种: a=a+b; b=a-b; a=a-b; 第二种: 异或:相同是0,不同是1 上面是整型的,那么字符串可以直接异或吗? ...
- "sfc/scannow" 修复系统,提示 "windows资源保护无法启动修复服务"(win7)
原因: ArcGIS9.3安装后对注册空间进行了限制. 解决方案: 1,输入 regeidt 打开注册表. 2,找到 HKEY_LOCAL_MACHINE\System\CurrentControlS ...
- js获取当前的时间(包含星期)
<script type="text/javascript"> setInterval("www_zzje_net.innerHTML=new ...
- NOIP201504推销员
#include<iostream> #include<cstring> #include<algorithm> #include<cmath> #in ...
- xode 中文乱码处理
find *.* -exec sh -c "iconv -f GB18030 -t UTF-8 {} > {}.txt" \;
- zepto自定义事件
<!--测试自定义事件 trigger--> <script> $(function () { var meEvent = $.Event("custom" ...