【C语言】杨氏矩阵


复制代码
#include <stdio.h>
int findnum(int* (*arr)[4], int r, int c, int k)
{
	// 先找出右上角的值
	int i = 0;
	int j = c - 1;
	while (i <= r && j >= 0)
	{
		if (k > arr[i][j])
		{
			i++;
		}
		else if (k < arr[i][j])
		{
			j--;
		}
		else
		{
			return 1;
		}
	}
	return 0;
}
int main()
{
	int arr[4][4] = { 1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7 };
	int k = 6;
	int ret = findnum(arr, 4, 4, k);
	if (ret == 1)
	{
		printf("存在!");
	}
	else
	{
		printf("不存在!");
	}
	return 0;
}
相关推荐
小南家的青蛙几秒前
LeetCode第773题 - 滑动谜题
算法·leetcode·职场和发展
Felven10 分钟前
C. Isamatdin and His Magic Wand!
c语言·数据结构·算法
AndrewHZ13 分钟前
【芯芯相印】什么是算法定点化?
pytorch·算法·芯片设计·模型量化·定点化·芯片算法·逻辑电路
数据科学小丫17 分钟前
算法:线性回归
算法·回归·线性回归
吗~喽18 分钟前
【C++】模板进阶
c语言·开发语言·c++
剪一朵云爱着25 分钟前
PAT 1131 Subway Map
算法·pat考试·图论
CoderYanger25 分钟前
动态规划算法-子序列问题(数组中不连续的一段):30.最长数对链
java·算法·leetcode·动态规划·1024程序员节
啦哈拉哈28 分钟前
【Python】知识点零碎学习1
数据结构·python·算法
多恩Stone31 分钟前
【3DV 进阶-10】Trellis 中的表示 SLat 理解(1)
人工智能·python·算法·3d·aigc
京井31 分钟前
从中序与后序遍历序列构造二叉树解题思路
c语言·算法