NC24835. [USACO 2009 Mar B]Plumbing the Pond
描述
输入描述
* Line 1: Two space-separated integers: R and C
* Lines 2..R+1: Line i+1 contains C space-separated integers that represent the depth of the pond across row i:
输出描述
* Line 1: A single integer that is the depth of the pond determined by following Bessie's rules.
示例1
输入:
4 3 0 1 0 1 2 0 1 5 1 2 3 4
输出:
1
说明:
The pond has 4 rows, 3 columns.C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 616K, 提交时间: 2019-09-15 21:05:50
#include<bits/stdc++.h> #define MAX_INT ((unsigned)(-1)>>1) #define MIN_INT (~MAX_INT) #define pi 3.1415926535898 using namespace std; int a[55][55]; int main(void) { int n,m;cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; } } int max1=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(a[i-1][j-1]==a[i][j]||a[i-1][j]==a[i][j]||a[i-1][j+1]==a[i][j]|| a[i][j-1]==a[i][j]||a[i][j+1]==a[i][j]||a[i+1][j-1]==a[i][j]|| a[i+1][j]==a[i][j]||a[i+1][j+1]==a[i][j]) max1=max(max1,a[i][j]); } } cout<<max1; return 0; }
C++11(clang++ 3.9) 解法, 执行用时: 4ms, 内存消耗: 604K, 提交时间: 2019-09-07 09:42:40
#include<bits/stdc++.h> using namespace std; int a[501][501],r,c,ans; int x[8]={-1,-1,-1,0,0,1,1,1}; int y[8]={-1,0,1,-1,1,-1,0,1}; int main() { cin>>r>>c; for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) { cin>>a[i][j]; } } for(int i=1;i<=r;i++) { for(int j=1;j<=c;j++) { for(int q=0;q<8;q++) if(a[i][j]==a[i+x[q]][j+y[q]]) ans=max(ans,a[i][j]); } } cout<<ans; }