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 ...
 
随机推荐
- gitlab的备份与恢复与迁移
			
一.gitlab的备份1.1 创建备份目录,并授权 1 2 3 4 [root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-no ...
 - Java操作Kafka执行不成功的解决方法,Kafka Broker Advertised.Listeners属性的设置
			
创建Spring Boot项目继承Kafka,向Kafka发送消息始终不成功.具体项目配置如下: <?xml version="1.0" encoding="UTF ...
 - jquery validate 增加过滤特殊字符的方法
			
jQuery.validator.addMethod("specialCharFilter", function(value, element) { var pattern = n ...
 - linux服务器上没有jar命令
			
在linux服务器上用jar命令解压jar包时,提示找不到jar命令. 但是用java -version查看jdk版本,又可以显示出jdk版本. echo $JAVA_HOME查看环境变量路径,找不到 ...
 - Dubbo学习笔记1:使用Zookeeper搭建服务治理中心
			
Zookeeper是Apache Hadoop的子项目,是一个树形的目录服务,支持变更推送,适合作为Dubbo服务的注册中心,工业强度较高,推荐生成环境使用. , 下面结合上图介绍Zookeeper在 ...
 - android 低功耗蓝牙使用
			
参考链接:http://blog.csdn.net/xubin341719/article/details/38584469 1.android 手机的低功耗蓝牙,又称BLE :BLE在andriod ...
 - 手写简化版printf函数
			
2019.02.01更新:经同学提醒,myprintf函数应有返回值为输出的字符数. 期末的大作业,手写一个myprintf函数,支持如下一些操作. 也就是 % -(负号控制左右对齐) 数(控制字段 ...
 - Java中关于变量的几种情况
			
Java中关于变量的几种情况 1.继承时变量的引用关系 class Animals { int age = 10; void enjoy() { System.out.println("An ...
 - JS合并单元格
			
在Web中经常需要合并单元格,例如对于下面一个表格: <!DOCTYPE html> <html> <head> <meta charset="UT ...
 - Count of Smaller Number before itself
			
Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 1 ...