ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)A ASCII Area

A:

  给你一个矩阵求'/' 和 '\' 围成的图形,简单签到题,有一些细节要考虑。

  题解:一行一行的跑,遇到'/'和'\' 就加0.5, 在面积里面的'.' 就加1.用一个flag来判断是否在围住的图形里面。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <algorithm>
 6 #include <cmath>
 7 #include <vector>
 8 #include <queue>
 9 #include <map>
10 #include <stack>
11 #include <set>
12 using namespace std;
13 typedef long long LL;
14 typedef unsigned long long uLL;
15 #define ms(a, b) memset(a, b, sizeof(a))
16 #define pb push_back
17 #define mp make_pair
18 #define eps 0.0000000001
19 #define IOS ios::sync_with_stdio(0);cin.tie(0);
20 const LL INF = 0x3f3f3f3f3f3f3f3f;
21 const int inf = 0x3f3f3f3f;
22 const int maxn = 100+10;
23 const int mod = 1e9+7;
24 char s[maxn][maxn];
25 int main() {
26 #ifdef LOCAL
27     freopen("input.txt", "r", stdin);
28 //    freopen("output.txt", "w", stdout);
29 #endif
30 //    IOS
31     
32     freopen("ascii.in", "r", stdin);
33     freopen("ascii.out", "w", stdout);
34 
35     int h, w;
36     scanf("%d%d", &h, &w);
37     for(int i = 0;i<h;i++)  scanf("%s", s[i]);
38 
39     double ans = 0;
40     for(int i = 0;i<h;i++){
41         int flag = 0;
42         for(int j = 0;j<w;j++){
43             if((s[i][j]=='/'||s[i][j]=='\\')&&flag==0){
44                 flag = 1;
45                 ans += 0.5;
46             }
47             else if(s[i][j]=='.'&&flag){
48                 ans+=1.0;
49             }
50             else if((s[i][j]=='/'||s[i][j]=='\\')&&flag){
51                 flag = 0;
52                 ans += 0.5;
53             }
54         }
55 //        printf("%.0f\n", ans);
56     }
57     printf("%.0f\n", ans);
58     return 0;
59 }
View Code
posted @ 2017-08-26 20:40  Dh_q  阅读(176)  评论(0编辑  收藏  举报