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 ...
随机推荐
- error C2143: 语法错误 : 缺少“;”(在“using”的前面)
class JJMenuScene : public cocos2d::CCLayer { public: // Here's a difference. Method 'init' in cocos ...
- Mysql查看连接端口及版本
C:\Users\Administrator>mysql -uroot -pEnter password: *****Welcome to the MySQL monitor. Commands ...
- 读取xml文件信息
static void Main(string[] args) { XmlTextReader reader = new XmlTextReader(@"D:\zy\visual studi ...
- for 迭代器遍历list map
1.map与list区别 list是对象集合,允许对象重复. map是键值对的集合,不允许key重复 2.list 与 list<类型> list不限制类型,也就是object类型 ...
- nodejs安装过程及视频地址
说实话在安装的过程中遇到了很多问题,包括npm install connect出错,主要是我之前安装了0.10版本之后安装4.X版本造成的,后面卸载没有卸载完全造成的,后面也就好了,网上说了很多重新设 ...
- 使用HTML5中的Canves标签制作时钟特效
<!DOCTYPE html > <html> <head> </head> <body> <canvas id="cloc ...
- linux挂载查看、添加与取消
挂载概念: 查看挂载:df 添加挂载mount:mount 挂载的源 目的点 mount /dev/sdb1 /mnt mount挂载常用参数(Option) -t 指定文件系统类型,例如:-t ex ...
- Symfony2之创建一个简单的web应用
Symfony2——创建bundle bundle就像插件或者一个功能齐全的应用,我们在应用层上开发的应用的所有代码,包括:PHP文件.配置文件.图片.css文件.js文件等都会包含在bu ...
- 棋盘上的距离 - Grids1657
棋盘上的距离 问题描述: 写一个程序,给定起始位置和目标位置,计算王.后.车.象从起始位置走到目标位置所需的最少步数. 王:横.直.斜都可以走,但每步限走一格. 后:横.直.斜都可以走,每步格数不受限 ...
- 关于KMP算法理解(快速字符串匹配)
参考:http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html 2016-08- ...