第十一届蓝桥杯大赛第二场省赛试题 C&C++ 研究生组-蛇形填数

761

solution1

cpp 复制代码
#include<stdio.h>
int main(){
	int a[50][50] = {0}, i = 1, j = 1, count = 1, op = 0;
	while(i < 40 && j < 40){
		a[i][j] = count++;
		if(!op) a[i][++j] = count++;
		while(j >= 2){
			a[++i][--j] = count++;
		}
		a[++i][j] = count++;
		while(i >= 2){
			a[--i][++j] = count++;
		}
		j++;
		op = 1;
	}
//	for(int i = 1; i < 21; i++){
//		for(int j = 1; j < 21; j++){
//			printf("%d ", a[i][j]);
//		}
//		printf("\n");
//	}
	printf("%d", a[20][20]);
	return 0;
}

solution2

cpp 复制代码
#include<stdio.h>
int main(){
	int a[50][50] = {0}, i = 1, j = 1, count = 1, op = 0;
	a[1][1] = count++;
	while(i < 40 && j < 40){
		a[i][++j] = count++;
		while(j >= 2){
			a[++i][--j] = count++;
		}
		a[++i][j] = count++;
		while(i >= 2){
			a[--i][++j] = count++;
		}
	}
//	for(int i = 1; i < 21; i++){
//		for(int j = 1; j < 21; j++){
//			printf("%d ", a[i][j]);
//		}
//		printf("\n");
//	}
	printf("%d", a[20][20]);
	return 0;
}
相关推荐
Logic1011 小时前
C语言/数据动态规划题解:翻转一次子数组后的最大子数组和——四状态DP(O(n)时间O(1)空间)
c语言·数据结构·动态规划·时间复杂度·算法题·状态机dp·最大子数组和
无小道1 小时前
C++——列表初始化
c++·列表初始化
blueSatchel1 小时前
c++action 编写(ros-humble)
c++·ros2
Logic1012 小时前
C语言/数据结构字符串题解:找出DNA序列中未配对的独特序列——排序+遍历(O(nlogn))
c语言·数据结构·字符串·数组·排序·时间复杂度·算法题
老赵的博客3 小时前
c++面试之从虚函数表到Rtti一次性讲清楚
c++·qt
Navigator_Z3 小时前
LeetCode //C - 1248. Count Number of Nice Subarrays
c语言·算法·leetcode
是隼人3 小时前
buuctf-pwn picoctf_2018_shellcode(ret2shellcode)题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
潜创微科技4 小时前
IT6520:USB-C 转 MIPI 高集成控制器,DP 1.4a 转 MIPI 单芯片搞定 4K120 显示
c语言·开发语言·低延迟·掌机·联阳
傲世仙尊4 小时前
System V 进程间通信详解:共享内存、消息队列与信号量(CSDN博客)
linux·开发语言·c++
cvby4 小时前
C++11
开发语言·c++