Long time ago, most of PCs were equipped with video cards that worked only in text mode. If the programmer wanted to show a picture on a screen, he had to use pseudographics or ASCII art like this on the right:
In this problem you are given a polygon, drawn using ASCII art. Your task is to calculate its area. The picture is formed using characters ‘.’, ‘\’, and ‘/’. Each character represents a unit square of the picture. Character ‘.’ represents an empty square, character ‘/’ — a square with a segment from the lower left corner to the upper right corner, and character ‘\’ — a square with a segment from the upper left corner to the lower right corner.
Input
The input file contains several test cases, each of them as described below. The first line of each case contains integer numbers h and w (2 ≤ h,w ≤ 100) — height and width of the picture. Next h lines contain w characters each — the picture drawn using ASCII art. It is guaranteed that the picture contains exactly one polygon without self-intersections and selftouches.
Output
For each test case, print to the output file one integer number — the area of the polygon.
Sample Input
4 4 /\/\ \../ .\.\ ..\/
Sample Output
8
#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<queue>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define mod 1e9+7
#define ll unsigned long long
#define MAX 1000000000
#define ms memset
#define maxn 105
using namespace std;
char mp[maxn];
int n,m;
/*
题目大意:给定图形统计多边形面积。
首先有\或者/的面积均为半个,
然后就是区分整块的面积是在内部还是在外部。
手动模拟,可预知其与/和\的数量有关,
当两者数量奇偶不同时计数。
*/
int cnt1=0,cnt2=0;
int ans=0;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
cnt1=0,cnt2=0,ans=0;
for(int i=0;i<n;i++)
{
scanf("%s",mp);getchar();
for(int j=0;j<m;j++)
{
if(mp[j]=='.')
{
if(cnt2%2!=cnt1%2) ans++;///规律题
}
else if(mp[j]=='/') cnt1++;
else cnt2++;
}
}
///cout<<ans<<endl;
///cout<<cnt1<<" "<<cnt2<<endl;
ans+=(cnt1+cnt2)/2;
printf("%d\n",ans);
}
return 0;
}