生活随笔
收集整理的這篇文章主要介紹了
【PAT乙级】1068 万绿丛中一点红 (20 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目地址
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std
;
int a
[1005][1005];
int dx
[8]={-1,-1,-1,0,0,1,1,1};
int dy
[8]={-1,0,1,-1,1,-1,0,1};
int n
,m
,k
;
bool f(int x
,int y
,int s
)
{for(int i
=0;i
<8;i
++){int tempx
=x
+dx
[i
];int tempy
=y
+dy
[i
];if(tempx
<=0||tempx
>m
||tempy
<=0||tempy
>n
) continue;if(abs(a
[tempx
][tempy
]-s
)<=k
) return false;}return true;
}
map
<int,int>mp
;
int main(void)
{cin
>>n
>>m
>>k
;for(int i
=1;i
<=m
;i
++) for(int j
=1;j
<=n
;j
++)cin
>>a
[i
][j
],mp
[a
[i
][j
]]++;int x
=0,y
=0,cnt
=0;for(int i
=1;i
<=m
;i
++){for(int j
=1;j
<=n
;j
++){if(mp
[a
[i
][j
]]>1) continue; if(f(i
,j
,a
[i
][j
])) x
=i
,y
=j
,cnt
++;}}if(!cnt
) cout
<<"Not Exist"<<endl
;if(cnt
>1) cout
<<"Not Unique"<<endl
;if(cnt
==1) printf("(%d, %d): %d\n",y
,x
,a
[x
][y
]);return 0;
}
總結
以上是生活随笔為你收集整理的【PAT乙级】1068 万绿丛中一点红 (20 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。