USACO 4.4 Frame Up
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的更多相关文章
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- 3.JAVA之GUI编程Frame窗口
创建图形化界面思路: 1.创建frame窗体: 2.对窗体进行基本设置: 比如大小.位置.布局 3.定义组件: 4.将组件通过add方法添加到窗体中: 5.让窗体显示,通过setVisible(tur ...
- iOS:frame访问、设置简化
看到一些程序都有这种写法,也不知道原创者是谁了.先在博客保存下. 在.m文件 #import "UIView+MyFrameCategory.h" @implementation ...
- IOS 杂笔-12(类别de巧用 有便于Frame的操作)
在实际开发中很多时候我们都为了控件frame的操作焦头烂额. 例如:我们只想要获取view的width. 我们可以这么操作:view.frame.size.width 有时我们想要改变view的wid ...
- 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 ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
- 如何给frame标签的src属性以及a标签的href属性自动设值
<frame src="" id="main" name="main" marginwidth="0" margi ...
- frame和bounds
- frame 是一个以**父视图**为坐标系的位置- bounds 是一个以**自身**为坐标系的位置- 如果改变了bounds 那么会影响子控件的显示位置
- 使用Java的Frame类编写的QQ登录界面
public static void main(String[] args) { Frame f = new Frame(); //关闭窗体 f.addWindowListener(new Windo ...
随机推荐
- webpack 多页面|入口支持和公共组件单独打包--转载
转载自:http://www.jb51.net/article/117490.htm 本篇主要介绍:如何自动构建入口文件,并生成对应的output:公共js库如何单独打包. 多入口文件,自动扫描入口. ...
- JS中浮点数精度误差解决
问题出现 0.1 + 0.2 = 0.30000000000000004 问题分析 对于浮点数的四则运算,几乎所有的编程语言都会有类似精度误差的问题,只不过在 C++/C#/Java 这些语言中已经封 ...
- [USACO4.3]逢低吸纳Buy Low, Buy Lower
https://daniu.luogu.org/problemnew/show/2687 求方案数: if(f[j]+1==f[i] && a[j]>a[i]) s[i]+=s[ ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- NGINX+TOMCAT实现反向代理
环境说明 NGINX: 192.168.10.10 TOMCAT: 192.168.10.11 NGINX部分 [root@nginx ~]# wget http://nginx.org/downlo ...
- 【CodeForces】961 F. k-substrings 字符串哈希+二分
[题目]F. k-substrings [题意]给定长度为n的串S,对于S的每个k-子串$s_ks_{k+1}...s_{n-k+1},k\in[1,\left \lceil \frac{n}{2} ...
- HDU 2062 Subset sequence (找规律)
题目链接 Problem Description Consider the aggregate An= { 1, 2, -, n }. For example, A1={1}, A3={1,2,3}. ...
- OpenCV LIBTIFF_4.0 link errors
以前用Caffe用的好好的,今天重装后居然报了很多这样的错误 /usr/lib/libopencv_highgui.so.' 1> /usr/lib/libopencv_highgui.so.' ...
- HTML5之2D物理引擎 Box2D for javascript Games 系列 翻外篇--如何结合createJS应用box2d.js
太久没有更新了,新年回来工作,突然有收到网友的邮件提问,居然还有人在关注,惭愧,找了下电脑上还有一点儿存着,顺便先发这一个番外篇吧,好歹可以看到真实的效果,等我考完英语,一定会更新下一章," ...
- SpringMVC控制器 跳转到jsp页面 css img js等文件不起作用 不显示
今天在SpringMVC转发页面的时候发现跳转页面确实成功,但是JS,CSS等静态资源不起作用: 控制层代码: /** * 转发到查看培养方案详情的页面 * @return */ @RequestMa ...