Long time ago, most of PCs were equipped with video cards that worked only intext mode. If the programmer wanted to show a picture on a screen, he had touse pseudographics or ASCII art like this on the right:In this problem you are given a polygon, drawn using ASCII art. Your taskis to calculate its area.The picture is formed using characters ‘.’, ‘\’, and ‘/’. Each character representsa unit square of the picture. Character ‘.’ represents an empty square,character ‘/’ — a square with a segment from the lower left corner to the upperright corner, and character ‘\’ — a square with a segment from the upper leftcorner 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 widthof 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
模拟+神奇的思路~
按块计数,如果是"\"或者"/",则面积加0.5,并且把now值^1,否则判断now值是否为1即可~
另外,\要输两个,超神奇的!
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,m,now;
float ans;
char a[101][101];
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=n;i++) scanf("%s",a[i]+1);ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(a[i][j]=='\\' || a[i][j]=='/')
{
now^=1;ans+=0.5;
}
else if(now) ans+=1;
}
if(ans==ans/1)
{
int now=ans;printf("%d\n",now);
}
else printf("%.1f\n",ans);
}
return 0;
}