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. jQuery合并单元格以及还原重置

    一.合并rowspan jQuery.fn.rowspan = function(colIdx) { return this.each(function(){ var that; $('tr', th ...

  2. Java并发编程原理与实战二十六:闭锁 CountDownLatch

    关于闭锁 CountDownLatch 之前在网上看到过一篇举例非常形象的例子,但不记得是出自哪里了,所以这里就当自己再重新写一篇吧: 例子如下: 我们每天起早贪黑的上班,父母每天也要上班,有一天定了 ...

  3. List(JDK1.7)(2)

    LinkedList List接口和Deque接口的一种双向链表实现.非同步的. 快速失败机制.ConcurrentModificationException 结点结构 插入结点 删除结点 add() ...

  4. Spring Aware容器感知技术

    Spring Aware是什么 Spring提供Aware接口能让Bean感知Spring容器的存在,即让Bean可以使用Spring容器所提供的资源. Spring Aware的分类 几种常用的Aw ...

  5. Django连接mysql常见错误

    1045, "Access denied for user 'root'@'localhost' (using password: YES)" 数据库的密码或用户名不对,查看set ...

  6. 钉钉头像大小设置 阿里cdn尺寸截取参数设置

    默认api的接口返回的avatar字段,是原始图片大小字段,尺寸和空间都是原始大小,如果想节省流量或统一尺寸,可以用阿里cdn自带的尺寸截取功能, 比如钉钉头像 avatar字段 返回值为原始大小ht ...

  7. js工作常见问题收集

    1. viewport <meta name="viewport" content="width=device-width,initial-scale=1.0,mi ...

  8. 【SLAM】安装 g2o_viewer

    2017年2月8日,那是一个阴天.为了完成高翔博士的<一起做RGB-D SLAM>教程,我在 Ubuntu 14.04 安装 g2o.遇到困难,怎奈我眼瞎,找错了方向,浪费时间,没有成功安 ...

  9. 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)

    因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...

  10. LINUX vim 修改文件 退出

    vim 保存退出, 先按ESC ,然后:wq(保存退出)W:write,写入 Q:quit,退出, 也可以直接输入X,代表WQ,也是保存退出 或者 先按ESC,再按shift+ZZ 也是保存退出 正常 ...