UVA 1641 POJ 4022 ASCII Area

统计斜杠出现了奇数次还是偶数次

点击打开链接

Long time ago, most of PCs were equipped with video cards that worked only in text mode. If theprogrammer wanted to show a picture on a screen, he had to use pseudographics or ASCII art like this:^..^(OO)/ \()()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 thepicture. Character ‘.’ represents an empty square, character ‘/’ — a square with a segment from thelower
left corner to the upper right corner, and character ‘\’ — a square with a segment from the upperleft corner to the lower right corner./\/\\../.\.\..\/InputThe first line of the input file contains integer numbers h and w (2 ≤ h, w ≤ 100) — height and width
ofthe 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 self-touches.OutputPrint to the output file one integer number — the area
of the polygon.Sample input and outputascii.in ascii.out4 4/\/\\../.\.\..\/8Page 1 of 16ACM ICPC 2011–2012, Northeastern European R

/* ***********************************************
Author        :CKboss
Created Time  :2015年02月02日 星期一 10时27分48秒
File Name     :POJ4022.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

int h,w;
char mp[200][200];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	while(scanf("%d%d",&h,&w)!=EOF)
	{
		memset(mp,0,sizeof(mp));
		for(int i=0;i<h;i++)
		{
			scanf("%s",mp[i]);
		}
		int area = 0;
		for(int i=0;i<h;i++)
		{
			int temp = 0;
			for(int j=0;j<w;j++)
			{
				if(mp[i][j]=='\\'||mp[i][j]=='/')
				{
					temp++; area+=1;
				}
				else if(mp[i][j]=='.')
				{
					if(temp%2) area+=2;
				}
			}
		}
		printf("%d\n",area/2);
	}

    return 0;
}
时间: 2024-08-05 05:44:41

UVA 1641 POJ 4022 ASCII Area的相关文章

poj 4022 ASCII Area dfs求二维面积

题意: 给一个有'/','\','.'组成的二维字符数组,求图中'/'和'\'组成的面积有多大. 分析: 每个'/'和'\'的格每个贡献1/2的面积,每个多边形内部的'.'贡献1的面积,关键是求多边形内部的'.'有多少个.一开始往上下左右4个方向搜wa了,原来内部的点可以斜着扩展,比如/./这种情况.但斜着搜要注意避免从多边形内部跑到外部的情况,比如题目中给的sample. 代码: //poj 4022 //sep9 #include <iostream> using namespace st

Uva 127 poj 1214 `Accordian&#39;&#39; Patience

 ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbour on

POJ 1265:Area

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4725   Accepted: 2135 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

UVA 124 &amp; POJ 1270 Following Orders(拓扑排序)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=60 http://poj.org/problem?id=1270 Following Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3806   Accepted: 1507 Description Or

UVa 1641 ASCII Area

题意: 就是用一个字符矩阵代表一个闭合的阴影部分,然后求阴影部分的面积. 分析: 一个'/'和'\'字符都代表半个小方块的面积. 关键就是判断'.'是否属于阴影部分,这才是本题的关键. 从第一列开始,从上到下扫面'/'和'\'字符的个数,如果是奇数,则'.'属于阴影部分,阴影面积加一. 1 #include <cstdio> 2 3 const int maxn = 100 + 10; 4 char map[maxn][maxn]; 5 6 int main() 7 { 8 //freopen

UVa 1641 ASCII Area (计算几何,水题)

题意:给定一个矩阵,里面有一个多边形,求多边形的面积. 析:因为是在格子里,并且这个多边形是很规则的,所以所有格子不是全属于多边形就是全不属于,或者一半,并且我们可以根据"/"和“\”的数目来知道,如果是奇数,那么就是属于, 偶数就是不属于. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #in

UVA 820 --- POJ 1273 最大流

找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的时候注意一下. 而且我居然犯了更愚蠢的错误,以为重边的时候需要选最大的,正解应该是累加.... 1 #include<stdio.h> 2 #include<queue> 3 #include<string.h> 4 #define INF 999999 5 using n

UVA (POJ 1598)Excuses, Excuses!

Excuses, Excuses! Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Excuses, Excuses!  Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid ser

poj 3940 Grey Area 浮点输出控制

水题,直接贴代码,注意几种控制浮点输出的方法:e格式,以指数形式输出实数.g格式:自动选f格式或e格式中较短的一种输出,且不输出无意义的零. 代码: //poj 3940 //sep9 #include <iostream> using namespace std; const int maxL=64; int cnt[maxL+10]; double color[maxL]; double area[maxL]; int main() { double p=0.10000; int n,w;