Frame Up

Consider the following five picture frames shown on an 9 x 8 array:

........   ........   ........   ........   .CCC....
EEEEEE.. ........ ........ ..BBBB.. .C.C....
E....E.. DDDDDD.. ........ ..B..B.. .C.C....
E....E.. D....D.. ........ ..B..B.. .CCC....
E....E.. D....D.. ....AAAA ..B..B.. ........
E....E.. D....D.. ....A..A ..BBBB.. ........
E....E.. DDDDDD.. ....A..A ........ ........
E....E.. ........ ....AAAA ........ ........
EEEEEE.. ........ ........ ........ ........ 1 2 3 4 5

Now place all five picture frames on top of one another starting with 1 at the bottom and ending up with 5 on top. If any part of a frame covers another frame, it hides that part of the frame below. Viewing the stack of five frames we see the following.

           .CCC...
ECBCBB..
DCBCDB..
DCCC.B..
D.B.ABAA
D.BBBB.A
DDDDAD.A
E...AAAA
EEEEEE..

Given a picture like this, determine the order of the frames stacked from bottom to top.

Here are the rules for this challenge:

  • The width of the frame is always exactly 1 character and the sides are never shorter than 3 characters.
  • It is possible to see at least one part of each of the four sides of a frame. A corner is part of two sides.
  • The frames will be lettered with capital letters, and no two frames will be assigned the same letter.

PROGRAM NAME: frameup

INPUT FORMAT

Line 1: Two space-separated integers: the height H (3 <= H <=30) and the width W (3 <= W <= 30).
Line 2..H+1: H lines, each with a string W characters wide.

SAMPLE INPUT (file frameup.in)

9 8
.CCC....
ECBCBB..
DCBCDB..
DCCC.B..
D.B.ABAA
D.BBBB.A
DDDDAD.A
E...AAAA
EEEEEE..

OUTPUT FORMAT

Print the letters of the frames in the order they were stacked from bottom to top. If there are multiple possibilities for an ordering, list all such possibilities -- in alphabetical order -- on successive lines. There will always be at least one legal ordering.

SAMPLE OUTPUT (file frameup.out)

EDABC

————————————————————————————————题解
只要不断判断有没有一个完全的矩形,去掉,用通配符代替即可如‘*’
但是我调试了比较长时间,被自己挖的坑坑到了
可是这就是一道简单的暴搜啊……上面是一道网络流题这USACO画风清奇……
 /*
ID: ivorysi
LANG: C++
TASK: frameup
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <string.h>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x7fffffff
#define ivorysi
#define mo 97797977
#define hash 974711
#define base 47
#define pss pair<string,string>
#define MAXN 30005
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
struct node {
string as;
char gr[][];
int used[];
node() {
as="";
memset(gr,'\0',sizeof(gr));
memset(used,,sizeof(used));
}
};
queue<node> q;
int h,w;
int top[],bottom[],lef[],righ[],view[];
vector<string> ans;
vector<int> le;
void init() {
scanf("%d%d",&h,&w);
node f;
siji(i,,h) {
scanf("%s",f.gr[i]+);
}
q.push(f);
fill(top,top+,inf);//fill(first,last,val);
fill(lef,lef+,inf);//这里写错了,应该是lef而不是lef+1
siji(i,,h) {
siji(j,,w) {
if(f.gr[i][j]<'A' || f.gr[i][j]>'Z' ) continue;
int k=f.gr[i][j]-'A';
if(!view[k]) {le.push_back(k);view[k]=;} if(i<top[k]) top[k]=i;
if(i>bottom[k]) bottom[k]=i;
if(j<lef[k]) lef[k]=j;
if(j>righ[k]) righ[k]=j; }
}
sort(le.begin(),le.end());
}
void bfs() {
init();
int cnt=;
int wrong=;
while(!q.empty()) {
node now=q.front();q.pop();
/*printf("-----%d-----\n",++cnt);
for(int i=1;i<=h;++i) {
printf("%s\n",now.gr[i]+1);
}*/
if(now.as.length()==le.size()) {ans.push_back(now.as);continue;}
node t=now;
xiaosiji(i,,le.size()) {
if(t.used[le[i]]) continue;
siji(j,lef[le[i]],righ[le[i]]) {
if(now.gr[top[le[i]]][j]=='*' || now.gr[top[le[i]]][j]=='A'+le[i]) {
t.gr[top[le[i]]][j]='*';
}
else {wrong=;goto fail;}
}
siji(j,lef[le[i]],righ[le[i]]) {
if(now.gr[bottom[le[i]]][j]=='*' || now.gr[bottom[le[i]]][j]=='A'+le[i]) {
t.gr[bottom[le[i]]][j]='*';
}
else {wrong=;goto fail;}
}
siji(j,top[le[i]],bottom[le[i]]) {
if(now.gr[j][lef[le[i]]]=='*' || now.gr[j][lef[le[i]]]=='A'+le[i]) {
t.gr[j][lef[le[i]]]='*';
}
else {wrong=;goto fail;}
}
siji(j,top[le[i]],bottom[le[i]]) {
if(now.gr[j][righ[le[i]]]=='*' || now.gr[j][righ[le[i]]]=='A'+le[i]) {
t.gr[j][righ[le[i]]]='*';
}
else {wrong=;goto fail;}
}
t.as.append(,'A'+le[i]);
t.used[le[i]]=;
q.push(t);
t=now;continue;
fail:
//printf("%d %c %d\n",cnt,le[i]+'A',wrong);
//printf("%d %d %d %d\n",top[le[i]],bottom[le[i]],lef[le[i]],righ[le[i]]);
t=now;
}
}
}
void solve() {
bfs();
xiaosiji(i,,ans.size()) {
reverse(ans[i].begin(),ans[i].end());
}
sort(ans.begin(),ans.end());
xiaosiji(i,,ans.size()) {
cout<<ans[i]<<endl;
}
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("frameup.in","r",stdin);
freopen("frameup.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}
												

USACO 4.4 Frame Up的更多相关文章

  1. Android动画效果之Frame Animation(逐帧动画)

    前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...

  2. 3.JAVA之GUI编程Frame窗口

    创建图形化界面思路: 1.创建frame窗体: 2.对窗体进行基本设置: 比如大小.位置.布局 3.定义组件: 4.将组件通过add方法添加到窗体中: 5.让窗体显示,通过setVisible(tur ...

  3. iOS:frame访问、设置简化

    看到一些程序都有这种写法,也不知道原创者是谁了.先在博客保存下. 在.m文件 #import "UIView+MyFrameCategory.h" @implementation ...

  4. IOS 杂笔-12(类别de巧用 有便于Frame的操作)

    在实际开发中很多时候我们都为了控件frame的操作焦头烂额. 例如:我们只想要获取view的width. 我们可以这么操作:view.frame.size.width 有时我们想要改变view的wid ...

  5. USACO . Your Ride Is Here

    Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...

  6. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  7. 如何给frame标签的src属性以及a标签的href属性自动设值

    <frame src="" id="main" name="main" marginwidth="0" margi ...

  8. frame和bounds

    - frame 是一个以**父视图**为坐标系的位置- bounds 是一个以**自身**为坐标系的位置- 如果改变了bounds 那么会影响子控件的显示位置

  9. 使用Java的Frame类编写的QQ登录界面

    public static void main(String[] args) { Frame f = new Frame(); //关闭窗体 f.addWindowListener(new Windo ...

随机推荐

  1. zz图像卷积与滤波的一些知识点

    Xinwei: 写的通俗易懂,终于让我这个不搞CV.不搞图像的外行理解卷积和滤波了. 图像卷积与滤波的一些知识点 zouxy09@qq.com http://blog.csdn.net/zouxy09 ...

  2. jquery中美元符号命名冲突问题解决

    在Jquery中,$是JQuery的别名,所有使用$的地方也都可以使用JQuery来替换,如$('#msg')等同于JQuery('#msg') 的写法.然而,当我们引入多个js库后,在另外一个js库 ...

  3. laravel带条件查询手动分页

    后台php代码: //手动分页 $users = $kaoqin; //打算输出的数组,二维 $perPage = 10; if ($request->has('page')) { $curre ...

  4. Linux下inittab文件详解

    /etc/inittab文件详解 Linux系统的启动过程为:加电自检-->根据BIOS中的设置从指定的设备启动-->找到设备MBR中的bootloader引导启动系统-->启动ke ...

  5. J - Clairewd’s message HDU - 4300(扩展kmp)

    题目链接:https://cn.vjudge.net/contest/276379#problem/J 感觉讲的很好的一篇博客:https://subetter.com/articles/extend ...

  6. WeX5入门之欢乐捕鱼打包

    一.下载欢乐捕鱼的素材包 https://files.cnblogs.com/files/wordblog/%E7%B4%A0%E6%9D%90.zip 二.把欢乐捕鱼素材放入项目中 并启动tomca ...

  7. [Ubuntu 14.04] 安装Flash && 安装QQ

    一.安装Flash 打开Firefox浏览器弹出的Flash安装提醒早都烦死了,那么Ubuntu14.04怎么安装Flash呢? 1.32位系统命令行安装: 第一步 更新库: sudo apt-get ...

  8. Tslib移植与分析【转】

    转自:http://blog.csdn.net/water_cow/article/details/7215308 目标平台:LOONGSON-1B开发板(mips32指令集)编译平台:x86PC-- ...

  9. skb_pull skb_push skb_put

    unsigned char *skb_pull(struct sk_buff *skb, int len)该函数将 data 指针向数据区的末尾移动,减少了len 字段的长度.该函数可用于从接收到的数 ...

  10. MySQL 5.7以后怎么查看索引使用情况?

    MySQL 5.7以后怎么查看索引使用情况? 0.在sys库中查看没用的索引 root@localhost [sys]>select * from schema_unused_indexes; ...