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 ...
随机推荐
- Java基础-面向对象第三大特性之多态(polymorphism)
Java基础-面向对象第三大特性之多态(polymorphism) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.多态概述 多态是继封装,继承之后,面向对象的第三大特性,多态的 ...
- Shell记录-Shell命令(其他)
top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. .命令格式 top [参数] Shell 2.命令功能 显示当前系统正在执行的 ...
- mongo转换副本集
本文介绍如何把独立的mongo实例转换成包含3个成员的副本集.开发和测试使用独立实例,生产使用副本集.如何安装独立的mongo实例本文不再赘述. 如果在部署副本集时还没有安装mongo实例,可以查看部 ...
- iview组件 eslint校验出错 Parsing error: x-invalid-end-tag
如下: 解决: 在.eslintrc.js文件中加上: rules: { // allow async-await 'generator-star-spacing': 'off', // allow ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- POJ 3308 Paratroopers(最小点权覆盖)(对数乘转加)
http://poj.org/problem?id=3308 r*c的地图 每一个大炮可以消灭一行一列的敌人 安装消灭第i行的大炮花费是ri 安装消灭第j行的大炮花费是ci 已知敌人坐标,同时消灭所有 ...
- NOI2006 最大获利(最大权闭合子图)
codevs 1789 最大获利 2006年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目描述 Description 新的技术正冲击着手机通讯市场,对于各大运营商来 ...
- 洛谷 P3835: 【模板】可持久化平衡树
题目传送门:洛谷P3835. 题意简述: 题面说的很清楚了. 题解: 考虑建立一棵每个节点都表示一个版本的树. 以初始版本 \(0\) 为根.对于第 \(i\) 个操作,从 \(v_i\) 向 \(i ...
- 【黑客免杀攻防】读书笔记17 - Rootkit基础
1.构建Rootkit基础环境 1.1.构建开发环境 VS2012+WDK8 1.2.构建基于VS2012的调试环境 将目标机.调试机配置在同一个工作组内 sVS2012配置->DRIVER-& ...
- 2016 最佳 Linux 发行版排行榜【转】
转自:http://www.linuxstory.org/the-best-linux-distros-of-2016/?utm_source=tuicool&utm_medium=refer ...