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 ...
随机推荐
- 腾讯2013笔试题—web前端笔试题 (老题练手)
问题描述(web前端开发附加题1): 编写一个javascript的函数把url解析为与页面的javascript.location对象相似的实体对象,如:url :'http://www.qq.co ...
- POJ3692 Kindergarten 【最大独立集】
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5317 Accepted: 2589 Desc ...
- Java基础知识强化46:StringBuffer类之判断一个字符串是否对称案例
1. 分析:判断一个字符串是否是一个对称的字符串,我们只需要把字符串的第1个字符和最后1个字符,第2个字符和倒数第2个字符,…… 比较的次数是长度除以2. 方法1:通过取取索引对应值来进行一一比对 ...
- 怎么设置tomcat管理员的用户名和密码
我们常常要进入Tomcat的管理界面来进行相应的操作,我们首先得有一个管理员的账户和密码.而Tomcat默认是没有管理员账户的,那么我们该怎么来添加一个管理员账户呢? 如果我们输入错误的Tomcat管 ...
- sqlserver获取当前id的前一条数据和后一条数据
一.条件字段为数值的情况 select * from tb where id=@id; --当前记录 select top 1 * from tb where id>@id order ...
- ORA-01172 ORA-01151
今天发现服务器的9号硬盘坏了,因做了RAID5,报障后也没理会,过了一会儿,有人反应说报表运行不出来,发现服务器所有的硬盘都不工作了,界面也没有反应,就强行关机,再开机可以进入系统,等维修人员来换了新 ...
- Swift中对计算属性的理解和对之前的补充
这个功能的重点作用应该是在计算上. 对于一般的属性,要么直接存一个,要么直接读一个,计算属性则可以根据所设置内容,进行一些修改或计算之类的, 比如: import UIKit class sample ...
- C#Dictionary 实例
Dictionary<int, string> dc = new Dictionary<int, string>(); dc.Add(, "看了"); dc ...
- C/C++中new关键字是否加括号的区别
代码: #include <iostream> using namespace std; class A{ public: int a; }; int main(){ A *a1 = ne ...
- Matlab 取子矩阵
MATLAB如何提取矩阵的子块 在matlab中如何提取一个矩阵的部分元素 1.提取大矩阵的一列.一行元素: 一列元素: A(:,j)表示提取A矩阵的第j列全部元素 一行元素: A(i,:)表示提 ...