当前位置:网站首页>2021-08-11 function pointer
2021-08-11 function pointer
2022-07-04 09:47:00 【skeet follower】
Young's matrix
There is a matrix of numbers , Each row of the matrix is incremented from left to right , The matrix is increasing from top to bottom , Please write a program to find out whether a number exists in such a matrix .
requirement : Time complexity is less than O(N);
#include<stdio.h>
void find_k(int a[3][3], int k, int x, int y)
{
// According to the characteristics of matrix increment , Starting from the upper right corner, the time complexity will be relatively small ;
int n= 0;
int m = y - 1;
// Abscissa cannot be greater than 3, The ordinate should be greater than or equal to 0;
while (n < x && m >= 0) {
// If smaller , Abscissa plus
if (a[n][m] < k) {
n++;
}
// If it's bigger , Minus ordinate
else if (a[n][m] > k) {
m--;
}
else {
printf(" Found the subscript is :%d %d", n, m);
return;
}
}
printf(" Can't find \n");
}
int main()
{
int k = 17;
int a[3][3] = { 1,2,3,4,5,6,7,8,9 };
find_k(a,k,3,3);
return 0;
}
边栏推荐
- [on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
- libmysqlclient. so. 20: cannot open shared object file: No such file or directory
- The child container margin top acts on the parent container
- How can people not love the amazing design of XXL job
- 2022-2028 global intelligent interactive tablet industry research and trend analysis report
- MySQL transaction mvcc principle
- Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
- C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
- 2022-2028 global probiotics industry research and trend analysis report
- 【leetcode】540. A single element in an ordered array
猜你喜欢

百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼

MySQL develops small mall management system

Hands on deep learning (34) -- sequence model

Hands on deep learning (43) -- machine translation and its data construction

Regular expression (I)

Hands on deep learning (45) -- bundle search

MATLAB小技巧(25)竞争神经网络与SOM神经网络

Sort out the power node, Mr. Wang he's SSM integration steps

Intelligent gateway helps improve industrial data acquisition and utilization

华为联机对战如何提升玩家匹配成功几率
随机推荐
Pueue data migration from '0.4.0' to '0.5.0' versions
Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
华为联机对战如何提升玩家匹配成功几率
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
How does idea withdraw code from remote push
Golang defer
Logstack configuration details -- elasticstack (elk) work notes 020
7-17 crawling worms (15 points)
MySQL transaction mvcc principle
什么是 DevSecOps?2022 年的定义、流程、框架和最佳实践
Kubernetes CNI 插件之Fabric
Machine learning -- neural network (IV): BP neural network
Leetcode (Sword finger offer) - 35 Replication of complex linked list
PHP is used to add, modify and delete movie information, which is divided into foreground management and background management. Foreground users can browse information and post messages, and backgroun
2022-2028 global seeder industry research and trend analysis report
C # use gdi+ to add text with center rotation (arbitrary angle)
Write a mobile date selector component by yourself
Kotlin 集合操作汇总
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail