# include <bits/stdc++.h>
using namespace std ;
int main() {
int m, n, k, temp ;
int i, j ;
cin>>m>>n>>k;
vector<vector<int>> a ;
for ( i = 0 ; i < m ; i ++ ) {
vector<int> t;
for ( j = 0 ; j < n ; j ++ ) {
cin>>temp;
t.push_back(temp) ;
}
a.push_back(t) ;
}
int mid = 0, l = 0, h = m * n - 1 ;
while ( l <= h ) {
mid = ( l + h ) / 2 ;
i = mid / n ;
j = mid % n ;
if ( a[i][j] == k )
break;
else if ( a[i][j] < k )
l = mid+1 ;
else
h = mid-1 ;
}
if ( a[i][j] != k ) cout << "Target cannot be found." << endl ;
else{
int x = i,y = j;
do{
mid--;
x = mid/n;
y = mid%n;
}while(a[x][y] == k);
mid++;
i = mid/n;
j = mid%n;
cout << (i+1) << " " << (j+1) << endl ;
}
}
C. 完美平方數 #include <iostream> #include <math.h> using namespace std; int numSquares(int n); int main() { int num, ans;
Jan 27, 2022E. 鐵路 本題源自於Onling Judge:514 - Rails 題目目標在於給定出站順序的前提下,利用已知入站順序1~N, 確定是否仍能夠以目標出站順序離開。 有一個簡單的想法,我們利用queue的特性來維護出站順序、 利用stack的特性來維護入站順序, 並依次比較它們的front/top是否相同,如果相同就安排出站(pop)。
Jan 27, 2022C. 組合 #include<bits/stdc++.h> using namespace std; vector<int> a; bool first=true,f=true; fstream input,output; void find(int g,vector<int> &can,int p){ if(!g){ if(!first){
Sep 19, 2021D. Flood Fill # include <bits/stdc++.h> using namespace std; int m[102][102]; struct Fill{ int x,y,t; };
Sep 16, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up