Ugly Windows

poj3923:http://poj.org/problem?id=3923

题意:给出两个整数n、m表示屏幕的长宽。屏幕上有一些窗口,每个窗口都是矩形的,窗口的边框用同一个大写字母来表示,不同的窗口的大写字母必定不同。

由于窗口的重叠,有些窗口的有些部分被其他窗口覆盖。但是,肯定有一些窗口在最顶端,不被其他任何窗口覆盖。我们称这些窗口为“顶端窗口”。你的任务就是找出所有的顶端窗口。

题解:简单的模拟。结果我错了很多次啊。首先,没有考虑到边框的内部一定要是‘.‘,然后是最坑就是每个窗口的高度和宽度都不能小于3,自己模拟能力还是很弱啊,要多打打。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<queue>
 6 using namespace std;
 7 bool visit[30],ans[30];
 8 char mp[102][102];
 9 struct Node{
10    int x1,y1;
11    int x2,y2;
12 }num[30];
13 int n,m;
14 int main(){
15     while(~scanf("%d%d",&n,&m)){
16         if(n==0&&m==0)break;
17         if(n<3||m<3)continue;
18         memset(visit,0,sizeof(visit));
19         memset(num,0,sizeof(num));
20         memset(mp,0,sizeof(mp));
21         memset(ans,0,sizeof(ans));
22         for(int i=0;i<=29;i++){
23             num[i].x1=num[i].y1=1000;
24             num[i].x2=num[i].y2=0;
25         }
26         for(int i=1;i<=n;i++)
27             for(int j=1;j<=m;j++){
28                 cin>>mp[i][j];
29                 if(mp[i][j]!=‘.‘){
30                     num[mp[i][j]-‘A‘].x1=min(num[mp[i][j]-‘A‘].x1,i);
31                     num[mp[i][j]-‘A‘].y1=min(num[mp[i][j]-‘A‘].y1,j);
32                     num[mp[i][j]-‘A‘].x2=max(num[mp[i][j]-‘A‘].x2,i);
33                     num[mp[i][j]-‘A‘].y2=max(num[mp[i][j]-‘A‘].y2,j);
34                     visit[mp[i][j]-‘A‘]=1;
35                 }
36             }
37         for(int i=0;i<=29;i++){
38             if(visit[i]){
39                 int t1=num[i].x1;
40                 int t2=num[i].y1;
41                 int t3=num[i].x2;
42                 int t4=num[i].y2;
43                 bool flag=false;
44                for(int j=t2;j<=t4;j++){
45                  if((mp[t1][j]!=(‘A‘+i))||(mp[t3][j]!=(‘A‘+i))){
46                     flag=true;
47                     break;
48                  }
49                }
50                 for(int j=t1;j<=t3;j++){
51                  if(mp[j][t2]!=(‘A‘+i)||mp[j][t4]!=(‘A‘+i)){
52                     flag=true;
53                     break;
54                  }
55                }
56                if(t3-t1<2||t4-t2<2)flag=true;
57             if(!flag)
58               ans[i]=1;
59             }
60         }
61         for(int i=0;i<=29;i++){
62            if(visit[i]){
63               for(int k=num[i].x1+1;k<num[i].x2;k++){
64                 for(int j=num[i].y1+1;j<num[i].y2;j++){
65                     if(mp[k][j]!=‘.‘)
66                         ans[i]=0;
67                 }
68               }
69            }
70         }
71         for(int i=0;i<=29;i++)
72             if(ans[i])
73             printf("%c",i+‘A‘);
74        printf("\n");
75     }
76 }

Ugly Windows

时间: 2024-08-16 14:24:03

Ugly Windows的相关文章

【HDOJ】2487 Ugly Windows

暴力解. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 105 5 6 char map[MAXN][MAXN]; 7 char visit[27]; 8 int n, m; 9 10 bool check(char c) { 11 int i, j; 12 int x1=MAXN, y1=MAXN, x2=-1, y2=-1; 13 14 for (i=0; i<n; ++i) { 15 for (j=0

POJ 3923 &amp; HDU 2487 Ugly Windows(模拟)

题目链接: PKU:http://poj.org/problem?id=3923 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2487 Description Sheryl works for a software company in the country of Brada. Her job is to develop a Windows operating system. People in Brada are incredibly cons

HDU 2487 Ugly Windows

欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Ugly Windows Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1481    Accepted Submission(s): 591 Problem Description Sheryl works for a software company in the c

1419 - Ugly Windows(暴力枚举)

题目链接 题意:在一个界面上有多个窗口,求没有被其他窗口覆盖的窗口的个数. 思路:直接暴力枚举每个窗口的长和宽,以确定右下角是否与左上角相同,如果相同再判断矩形内部有没有被其他窗口覆盖到,注意边界覆盖也是算被覆盖到. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 10

hdu 2487 Ugly Windows 模拟

#include <cstdio> #include <iostream> #include <cstring> #include <vector> using namespace std; char map[110][110]; int n,m; #define inf 100000 struct node { int x,y; }; vector <node> nn; int main() { while(1) { int i,j,k; sc

POJ 3923 &amp;amp; HDU 2487 Ugly Windows(模拟)

题目链接: PKU:http://poj.org/problem? id=3923 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2487 Description Sheryl works for a software company in the country of Brada. Her job is to develop a Windows operating system. People in Brada are incredibly con

UVA - 1419 Ugly Windows

题目大意:给出一张图,模仿电脑窗口,问有哪些窗口未被其他窗口覆盖. 解题思路:水题.按顺序枚举字母,在地图中找到第一个该字母的点,向右向下搜索.最后看能不能构成右下角.唯一要注意的是,窗口可能会嵌套tc.要判断窗口中有没有其他字母. #include <cstdio> int main() { char s[110][110]; int n, m; while (scanf("%d%d", &n, &m) && n + m) { int an

Windows API参考大全新编

书名:新编Windows API参考大全 作者:本书编写组 页数:981页 开数:16开 字数:2392千字 出版日期:2000年4月第二次印刷 出版社:电子工业出版社 书号:ISBN 7-5053-5777-8 定价:98.00元 内容简介 作为Microsoft 32位平台的应用程序编程接口,Win32 API是从事Windows应用程序开发所必备的.本书首先对Win32 API函数做完整的概述:然后收录五大类函数:窗口管理.图形设备接口.系统服务.国际特性以及网络服务:在附录部分,讲解如何

08年acm区域赛北京赛区 部分题解题报告

08年区域赛北京赛区 http://poj.org/searchproblem?field=source&key=Beijing+2008 POJ 3921 Destroying the bus stations 题目还是比较难的,当时的榜似乎只有4/25的通过/提交,其实题目数据很水.学长转换模型写了网络流求最小割,可以AC,不过自己造了个数据推翻了正确性.我写了个很挫的bfs套bfs,外层是最小的删除点数,内层是求最短路,数据很水可以AC.但比较蛋疼的在于bfs耗内存,而且队列中的点数是阶乘