UVA 1641 统计面积(数学规律)

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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值