UVa Problem 10051
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int cube[][];
int max_col[];
int tmp_col[];
struct{
int p;
int wh;
} pre[][]; struct c{
int p;
int wh;
}st_col[],tmp_st[];
int ans,ansc,answ; int main(){
int n; int T=;
while(scanf("%d",&n),n){
for(int i=;i<=;i++)
st_col[i].p=st_col[i].wh=-;
T++;
if(T>) printf("\n");
ans=answ=ansc=-;
memset(max_col,,sizeof(max_col));
for(int i=;i<=n;i++){
for(int j=;j<=;j++)
scanf("%d",&cube[i][j]);
}
for(int i=n;i>=;i--){
for(int j=;j<=;j++){
tmp_col[cube[i][j]]=max_col[cube[i][j]];
tmp_st[cube[i][j]]=st_col[cube[i][j]];
}
for(int k=;k<=;k++){
if(k%){
if(tmp_col[cube[i][k]]+>max_col[cube[i][k+]]){
max_col[cube[i][k+]]=tmp_col[cube[i][k]]+;
if(ans<max_col[cube[i][k+]]){
ans=max_col[cube[i][k+]];
ansc=i;
answ=k+;
}
pre[i][k+].p=tmp_st[cube[i][k]].p;
pre[i][k+].wh=tmp_st[cube[i][k]].wh;
st_col[cube[i][k+]].p=i;
st_col[cube[i][k+]].wh=k+;
}
}
else{
if(tmp_col[cube[i][k]]+>max_col[cube[i][k-]]){
max_col[cube[i][k-]]=tmp_col[cube[i][k]]+;
if(ans<max_col[cube[i][k-]]){
ans=max_col[cube[i][k-]];
ansc=i;
answ=k-;
}
pre[i][k-].p=tmp_st[cube[i][k]].p;
pre[i][k-].wh=tmp_st[cube[i][k]].wh;
st_col[cube[i][k-]].p=i;
st_col[cube[i][k-]].wh=k-;
}
}
}
}
printf("Case #%d\n",T);
printf("%d\n",ans);
int p=ansc,pw=answ;
while(p!=-){
printf("%d ",p);
if(pw==){
printf("front\n");
}
if(pw==) printf("back\n");
if(pw==) printf("left\n");
if(pw==) printf("right\n");
if(pw==) printf("top\n");
if(pw==) printf("bottom\n");
int tp=p,tw=pw;
p=pre[tp][tw].p;
pw=pre[tp][tw].wh;
}
}
return ;
}
UVa Problem 10051的更多相关文章
- 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
// The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...
- UVA Problem B: Fire!
Problem B: Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and t ...
- UVa Problem 10132 File Fragmentation (文件还原) 排列组合+暴力
题目说每个相同文件(01串)都被撕裂成两部分,要求拼凑成原来的样子,如果有多种可能输出一种. 我标题写着排列组合,其实不是什么高深的数学题,只要把最长的那几个和最短的那几个凑一起,然后去用其他几个验证 ...
- UVa Problem 100 The 3n+1 problem (3n+1 问题)
参考:https://blog.csdn.net/metaphysis/article/details/6431937 #include <iostream> #include <c ...
- [题解]UVa 11082 Matrix Decompressing
开始眨眼一看怎么也不像是网络流的一道题,再怎么看也觉得像是搜索.不过虽然这道题数据范围很小,但也不至于搜索也是可以随随便便就可以过的.(不过这道题应该是special judge,因为一题可以多解而且 ...
- [题解]UVa 10891 Game of Sum
在游戏的任何时刻剩余的都是1 - n中的一个连续子序列.所以可以用dp[i][j]表示在第i个数到第j个数中取数,先手的玩家得到的最大的分值.因为两个人都很聪明,所以等于自己和自己下.基本上每次就都是 ...
- [题解]UVa 10635 Prince and Princess
讲一下题目大意,就是有两个长度为p + 1和q + 1的序列,求它们的LCS. 如果用O(pq)的算法对于这道题来说还是太慢了.所以要另外想一些方法.注意到序列中的所有元素都不相同,所以两个序列中数对 ...
- UVa 11019 Matrix Matcher - Hash
题目传送门 快速的vjudge传送门 快速的UVa传送门 题目大意 给定两个矩阵S和T,问T在S中出现了多少次. 不会AC自动机做法. 考虑一维的字符串Hash怎么做. 对于一个长度为$l$的字符串$ ...
- UVa 11997 K Smallest Sums - 优先队列
题目大意 有k个长度为k的数组,从每个数组中选出1个数,再把这k个数进行求和,问在所有的这些和中,最小的前k个和. 考虑将前i个数组合并,保留前k个和.然后考虑将第(i + 1)个数组和它合并,保留前 ...
随机推荐
- Python中的math和保留小数位数方法
转载自 http://xukaizijian.blog.163.com/blog/static/17043311920111163272414/ math模块实现了许多对浮点数的数学运算函数. 这些 ...
- hdu3511-Prison Break
纪念一下人生中第一道扫描线算法的题.....其实不是严格上的第一道...第一次遇到的那个至今没过..... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pi ...
- 【原创分析帖】据说Google内部有史以来最难的一道面试题
逛技术平台的时候,刷到一道算法题,一眼看去,就被其开头吸引了: 摘自知乎某 Google 分布式大神的一道题,技术是Google内部出的有史以来最难的一道题 嗯,距离下班还有一段时间,就看看把. 题目 ...
- 【poj1995】快速幂
题目大意 求a^b %p 1≤a,b,p≤10^9 思路 时间O(10^9)一定会爆T,采用数学方法+位运算,得到O(log b)的快速幂算法 代码 #include<cstdio> #i ...
- bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6
自己写了个Django系统,用到了Django-bootstrap3结果在浏览器控制台发现报错:bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaS ...
- Laravel5.1学习笔记10 系统架构2 应用程序结构
应用程序结构 简介 根目录 App 目录 为应用程序设置命名空间 简介 默认的 Laravel 应用程序结构是为了给无论构建大型还是小型应用程序都提供一个良好的开始.当然,你可以依照喜好自由地组织应用 ...
- python--5、模块
模块 程序的代码根据作用分散写入多个文件,这些文件相互引用,以实现程序的功能,这些文件即称之为”模块“.自己定义的函数或者变量为了防止在解释器中执行完退出后丢失,需要把代码写到文件中,再直接执行,称为 ...
- 【PostgreSQL-9.6.3】修改监听的IP和端口
在数据目录下编辑postgresql.conf文件,我的数据目录是/usr/local/pgsql/data vi postgresql.conf 找到如下内容: ... #listen_addres ...
- SQL SERVER2012 安装
- Deutsch lernen (08)
1. empfehlen - empfahl - hat empfohlen 推荐:劝说,劝告 Können Sie mir einen guten Artz empfehlen? jemand e ...