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("in.txt", "r", stdin);
 9     int h, w;
10     while(scanf("%d%d", &h, &w) == 2)
11     {
12         for(int i = 0; i < h; ++i) scanf("%s", map[i]);
13         int cnt = 0;
14         bool flag = false;
15         for(int i = 0; i < w; ++i)
16             for(int j = 0; j < h; ++j)
17             {
18                 if(map[j][i] == ‘/‘ || map[j][i] == ‘\\‘)
19                 {
20                     cnt++;
21                     flag = !flag;
22                 }
23                 else if(flag) cnt += 2;
24             }
25
26         printf("%d\n", cnt / 2);
27     }
28
29     return 0;
30 }

代码君

时间: 2024-11-10 13:58:34

UVa 1641 ASCII Area的相关文章

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

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

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

poj 4022 ASCII Area dfs求二维面积

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

[UVA Live 12931 Common Area]扫描线

题意:判断两个多边形是否有面积大于0的公共部分 思路:扫描线基础. #pragma comment(linker, "/STACK:10240000") #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #de

UVA 10522 - Height to Area(计算几何)

这题就海伦公式带进去就可以了.. 要注意的是,这题的样例,是输入n次错误的输入才停止..,输入的可能是负数. 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-8; int t; double Ha, Hb, Hc; int dcmp(double x) { if (

UVA 10522 Height to Area(知三角形三高求面积)

思路:海伦公式, AC代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 scanf("%d",&n); 7 double ha, hb, hc, a, b, c; 8 while(~scanf("%lf %lf %lf",&ha,&hb,&hc)) 9 { 10 a = 2.0 / ha; 11 b = 2.0

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

UVA 11178 Morley&#39;s Theorem 计算几何

计算几何: 最基本的计算几何,差积  旋转 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the line

UVA - 12075 Counting Triangles

Description Triangles are polygons with three sides and strictly positive area. Lattice triangles are the triangles all whose vertexes have integer coordinates. In this problem you have to find the number of lattice triangles in anMxN grid. For examp