GDPU 竞赛技能实践 天码行空3

2024-03-14 03:04

本文主要是介绍GDPU 竞赛技能实践 天码行空3,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. 五星填数

在这里插入图片描述

💖 源代码

public class Main
{static int[] nums = new int[11];static boolean[] used = new boolean[13];static long ans = 0;static{used[7] = true;used[11] = true;}public static void main(String[] args){dfs(1);System.out.println(ans / 10);// 除10去除镜像和旋转的重复项}private static void dfs(int idx){if (idx == 11){check();return;}for (int i = 1; i <= 12; i++){if (!used[i]){used[i] = true;nums[idx] = i;dfs(idx + 1);used[i] = false;}}}private static void check(){int a = nums[1] + nums[3] + nums[6] + nums[9];int b = nums[1] + nums[4] + nums[7] + nums[10];int c = nums[2] + nums[6] + nums[8] + nums[10];int d = nums[2] + nums[3] + nums[4] + nums[5];int e = nums[5] + nums[7] + nums[8] + nums[9];if (a == b && b == c && c == d && d == e)ans++;}
}

💖 输出

12

2. 遍历黑点

在这里插入图片描述

💖 源代码

public class Main
{static int n = 4, m = 5;static char[][] map = new char[][] { { '.', '.', '.', '.', '#' }, { '.', '.', '.', '.', '.' },{ '#', '@', '.', '.', '.' }, { '.', '#', '.', '.', '#' } };static boolean[][] st = new boolean[n][m];static boolean[][] out = new boolean[n][m];static int[] dx = { 0, 1, 0, -1 };static int[] dy = { 1, 0, -1, 0 };public static void main(String[] args){int sx = 0, sy = 0;// 起点坐标for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)if (map[i][j] == '@'){sx = i;sy = j;}
//		从起点开始搜索dfs(sx, sy);}private static void dfs(int x, int y){if (!out[x][y]){out[x][y] = true;System.out.println("黑点:[" + x + "][" + y + "]");}for (int i = 0; i < 4; i++){int xx = x + dx[i];int yy = y + dy[i];if (xx >= 0 && xx < n && yy >= 0 && yy < m && !st[xx][yy] && map[xx][yy] == '.'){st[x][y] = true;dfs(xx, yy);st[xx][yy] = false;}}}
}

💖 输出

黑点:[2][1]
黑点:[2][2]
黑点:[2][3]
黑点:[2][4]
黑点:[1][4]
黑点:[1][3]
黑点:[1][2]
黑点:[1][1]
黑点:[1][0]
黑点:[0][0]
黑点:[0][1]
黑点:[0][2]
黑点:[0][3]
黑点:[3][3]
黑点:[3][2]

3. 门牌编号

💖 源代码

public class Main
{static int ans = 0;static void cal(int x){while (x != 0){int t = x % 10;if (t == 2)ans++;x /= 10;}}public static void main(String[] args){for (int i = 1; i <= 2020; i++)cal(i);System.out.println(ans);}
}

💖 输出

624

这篇关于GDPU 竞赛技能实践 天码行空3的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/807011

相关文章

Spring Security简介、使用与最佳实践

《SpringSecurity简介、使用与最佳实践》SpringSecurity是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架,本文给大家介绍SpringSec... 目录一、如何理解 Spring Security?—— 核心思想二、如何在 Java 项目中使用?——

防止Linux rm命令误操作的多场景防护方案与实践

《防止Linuxrm命令误操作的多场景防护方案与实践》在Linux系统中,rm命令是删除文件和目录的高效工具,但一旦误操作,如执行rm-rf/或rm-rf/*,极易导致系统数据灾难,本文针对不同场景... 目录引言理解 rm 命令及误操作风险rm 命令基础常见误操作案例防护方案使用 rm编程 别名及安全删除

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

PHP应用中处理限流和API节流的最佳实践

《PHP应用中处理限流和API节流的最佳实践》限流和API节流对于确保Web应用程序的可靠性、安全性和可扩展性至关重要,本文将详细介绍PHP应用中处理限流和API节流的最佳实践,下面就来和小编一起学习... 目录限流的重要性在 php 中实施限流的最佳实践使用集中式存储进行状态管理(如 Redis)采用滑动

ShardingProxy读写分离之原理、配置与实践过程

《ShardingProxy读写分离之原理、配置与实践过程》ShardingProxy是ApacheShardingSphere的数据库中间件,通过三层架构实现读写分离,解决高并发场景下数据库性能瓶... 目录一、ShardingProxy技术定位与读写分离核心价值1.1 技术定位1.2 读写分离核心价值二

深入浅出Spring中的@Autowired自动注入的工作原理及实践应用

《深入浅出Spring中的@Autowired自动注入的工作原理及实践应用》在Spring框架的学习旅程中,@Autowired无疑是一个高频出现却又让初学者头疼的注解,它看似简单,却蕴含着Sprin... 目录深入浅出Spring中的@Autowired:自动注入的奥秘什么是依赖注入?@Autowired

MySQL分库分表的实践示例

《MySQL分库分表的实践示例》MySQL分库分表适用于数据量大或并发压力高的场景,核心技术包括水平/垂直分片和分库,需应对分布式事务、跨库查询等挑战,通过中间件和解决方案实现,最佳实践为合理策略、备... 目录一、分库分表的触发条件1.1 数据量阈值1.2 并发压力二、分库分表的核心技术模块2.1 水平分

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

Java整合Protocol Buffers实现高效数据序列化实践

《Java整合ProtocolBuffers实现高效数据序列化实践》ProtocolBuffers是Google开发的一种语言中立、平台中立、可扩展的结构化数据序列化机制,类似于XML但更小、更快... 目录一、Protocol Buffers简介1.1 什么是Protocol Buffers1.2 Pro

linux安装、更新、卸载anaconda实践

《linux安装、更新、卸载anaconda实践》Anaconda是基于conda的科学计算环境,集成1400+包及依赖,安装需下载脚本、接受协议、设置路径、配置环境变量,更新与卸载通过conda命令... 目录随意找一个目录下载安装脚本检查许可证协议,ENTER就可以安装完毕之后激活anaconda安装更