当前位置: 首页 > news >正文

十四届蓝桥杯省赛Java B组 合并区域

 

就是将两个矩阵进行拼接,两矩阵可以旋转90 180 270 度。

因为数据比较小,所以这基本上就是一个大的枚举模拟加搜索,直接暴力求解。

import java.io.*;
import java.util.*;public class Main{static int n;static int N = 101;static int mod = (int)1e9 + 7;static StreamTokenizer stt = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));static int[][] f = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
//	static int[][] ff = {{0, -1, 0}, {0, 0, 1}, {0, 1, 0}, {0, 0, -1}, {1, 0, 0}, {-1, 0, 0}};
//	static int[] month = {0, 31,28,31,30,31,30,31,31,30,31,30,31};static int[][] o = new int[N][N];static int[][] p = new int[N][N];static int[][] m = new int[3 * N][3 * N];static int maxi;private static int dfs(int x, int y) {int k = 1;m[x][y] = 0;for(int i = 0; i < 4; i ++) {int nx = x + f[i][0], ny = y + f[i][1];if(nx < 1 || nx > 3 * n || ny < 1 || ny > 3 * n || m[nx][ny] == 0) continue;k += dfs(nx, ny);}return k;}private static void draw(int bx, int by, int[][] o2) {for(int i = bx, ii = 1; ii <= n; ii ++, i ++) {for(int j = by, jj = 1; jj <= n; jj ++, j ++) {m[i][j] = o2[ii][jj];}}}static void asd(int x, int y) throws IOException {// 在地图上画o矩阵draw(n + 1, n + 1, o);// 在地图上画p矩阵draw(x, y, p);// 分别枚举o矩阵和p矩阵所有的1进行深搜for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++) {int nx = i + n, ny = j + n;if(m[nx][ny] == 1)maxi = Math.max(maxi, dfs(nx, ny));}}for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j++) {int nx = i + x - 1, ny = j + y - 1;if(m[nx][ny] == 1) maxi = Math.max(maxi, dfs(nx, ny));}}}private static void sov() throws IOException {// 在一个三倍大的地图中,枚举p矩阵的坐上角顶点,默认o在中心的n阶矩阵位置for(int i = 1; i <= 2 * n + 1; i ++) {asd(1, i);asd(2 * n + 1, i);asd(i, 1);asd(i, 2 * n + 1);}}static void rotate() {int[][] s = new int[N][N];for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++) {s[j][n - i + 1] = o[i][j];}}for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++) {o[i][j] = s[i][j];}}}static void sovle() throws Exception {n = readInt();for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++) {o[i][j] = readInt();}}for(int i = 1; i <= n; i ++) {for(int j = 1; j <= n; j ++) {p[i][j] = readInt();}}maxi = 0;
//		rotate();
//		for(int i = 1; i <= n; i ++){
//			for(int j = 1; j <= n; j ++) {
//				bw.write(o[i][j] + " ");
//			}
//			bw.write("\n");
//		}for(int i = 0; i < 4; i ++) {// 旋转o矩阵rotate();// 拼接两矩阵求解sov();}bw.write(maxi + "\n");}public static void main(String args[]) throws Exception {int t = 1;
//		t = Integer.parseInt(br.readLine());
//		t = readInt();while((t --) > 0) {
//		while((n = Integer.parseInt(br.readLine())) != 0) {sovle();}bw.flush();bw.close();}static int readInt() {try {stt.nextToken();} catch (IOException e) {e.printStackTrace();}return (int)stt.nval;}
}

http://www.lryc.cn/news/318973.html

相关文章:

  • SpringBoot高级
  • 机试:偶数分解
  • 一周学会Django5 Python Web开发-Jinja3模版引擎-安装与配置
  • python前端开发
  • web学习笔记(三十三)
  • flask库
  • 专业无网设备如何远程运维?向日葵远程控制能源场景案例解析
  • 基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的稻田虫害检测系统详解(深度学习+Python代码+UI界面+训练数据集)
  • 实现upt下客户端用tftp文件传输协议编写客户端发送下载文件
  • 什么软件可以改ip地址
  • C#,文字排版的折行问题(Word-wrap problem)的算法与源代码
  • VUE+VScode+elementUI开发环境
  • 第十四届蓝桥杯省赛真题 Java A 组【原卷】
  • 可视化展示与交互编辑:探索3D Web轻量化平台HOOPS WEB Platform在BIM中的新可能性
  • Linux(centos)环境下安装Nginx的步骤文档
  • AI毕业论文降重GPTS,避免AI检测,高效完成论文
  • 什么是线程死锁?形成死锁的四个必要条件是什么?如何避免线程死锁?
  • webpack一些常用的Loader和Plugin
  • SpringCloud Bus 消息总线
  • 汽车屏类产品(五):仪表Cluster常用芯片i.MX117x
  • SQLiteC/C++接口详细介绍之sqlite3类(三)
  • Xcode调试Qt 源码
  • CVE-2019-5782:kArgumentsLengthType 设置偏小导致优化阶段可以错误的去除 CheckBound 节点
  • uni-app微信小程序上拉加载,下拉刷新
  • HTML案例-2.标签综合练习
  • C++中的多值返回:解锁函数返回值的神奇力量
  • D咖智能咖啡机:营业利器,品质与效率的完美结合
  • 江科大stm32学习笔记【6-2】——定时器定时中断定时器外部时钟
  • go优雅重试
  • Python最常用的库