Codeforces Round #209 (Div. 2) Problem A Table(找规律)

这道题一开始想了好一会以为是DP,后来邝神一点播立马就知道怎么做了。

当有一个点在边缘的时候两次其余为四次。

前一种情况只需要选两次那个点就行了,其他情况随便你怎么枚举都是4次。

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 int n, m, map[100][100];
 9 
10 int main()
11 {
12 //    freopen("in.txt", "r", stdin);
13 
14 
15     while(scanf("%d%d", &n, &m)!=EOF)
16     {
17         int ans = 4;
18         for(int i=1; i<=n; i++){
19             for(int j=1; j<=m; j++){
20                 scanf("%d", &map[i][j]);
21                 if(map[i][j] && (i==n || j==m || i==1 || j==1)) ans = 2;
22             }
23         }
24         printf("%d
", ans);
25 
26     }
27     return 0;
28 }
View Code
奔跑吧!少年!趁着你还年轻
原文地址:https://www.cnblogs.com/shu-xiaohao/p/3404028.html