UVa 1641 ASCII Area

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值