import java.util.*;
import java.math.*; public class Main {
public static void main(String[] args) { Scanner sc = new Scanner(System.in);
int aPos = sc.nextInt();
int aMov = sc.nextInt();
int aThr = sc.nextInt();
int bPos = sc.nextInt();
int bMov = sc.nextInt();
int bThr = sc.nextInt();
int cPos = sc.nextInt();
int cMov = sc.nextInt();
int cThr = sc.nextInt();
sc.close(); Solution s = new Solution();
s.start(aPos, aMov, aThr, bPos, bMov, bThr, cPos, cMov, cThr);
}
} class Solution {
private int maxLength = 0; private int aMov;
private int aThr;
private int bMov;
private int bThr;
private int cMov;
private int cThr; public void start(int aPos, int aMov, int aThr,
int bPos, int bMov, int bThr,
int cPos, int cMov, int cThr) {
this.aMov = aMov;
this.aThr = aThr;
this.bMov = bMov;
this.bThr = bThr;
this.cMov = cMov;
this.cThr = cThr;
recursion(aPos, bPos, cPos, 511, 0, 0, 0);
System.out.println(this.maxLength);
} public void recursion(int curLengthA, int curLengthB, int curLengthC, int movStates, int aPos, int bPos, int cPos) {
int curMax = max_3(curLengthA, curLengthB, curLengthC);
if(maxLength < curMax)
maxLength = curMax; if(movStates == 0 || curLengthA < 0 || curLengthB < 0 || curLengthC < 0)
return ; //Walk
if( ((movStates & 448) == 256 || (movStates & 448) == 448 ) && aPos == 0) {
for(int i = 1; i <= this.aMov; i++) {
if(curLengthA + i != curLengthB && curLengthA + i != curLengthC)
recursion(curLengthA + i, curLengthB, curLengthC, movStates & 255, aPos, bPos, cPos);
if(curLengthA - i != curLengthB && curLengthA - i != curLengthC)
recursion(curLengthA - i, curLengthB, curLengthC, movStates & 255, aPos, bPos, cPos);
}
}
if( ((movStates & 56) == 32 || (movStates & 56) == 56 ) && bPos == 0) {
for(int i = 1; i <= this.bMov; i++) {
if(curLengthB + i != curLengthA && curLengthB + i != curLengthC)
recursion(curLengthA, curLengthB + i, curLengthC, movStates & 479, aPos, bPos, cPos);
if(curLengthB - i != curLengthA && curLengthB - i != curLengthC)
recursion(curLengthA, curLengthB - i, curLengthC, movStates & 479, aPos, bPos, cPos);
}
}
if( ((movStates & 7) == 4 || (movStates & 7) == 7 ) && cPos == 0) {
for(int i = 1; i <= this.cMov; i++) {
if(curLengthC + i != curLengthB && curLengthC + i != curLengthA)
recursion(curLengthA, curLengthB, curLengthC + i, movStates & 507, aPos, bPos, cPos);
if(curLengthC - i != curLengthB && curLengthC - i != curLengthA)
recursion(curLengthA, curLengthB, curLengthC - i, movStates & 507, aPos, bPos, cPos);
}
} // lift
if(Math.abs(curLengthA - curLengthB) == 1 && (movStates & 128) == 128 && aPos == 0 && bPos == 0) // a lift b
recursion(curLengthA, curLengthA, curLengthC == curLengthB ? curLengthA : curLengthC, movStates & 383, 0, 1, cPos == 1 ? 2 : 0);
if(Math.abs(curLengthA - curLengthB) == 1 && (movStates & 16) == 16 && aPos == 0 && bPos == 0) // b lift a
recursion(curLengthB, curLengthB, curLengthC == curLengthA ? curLengthB : curLengthC, movStates & 495, 1, 0, cPos == 1 ? 2 : 0);
if(Math.abs(curLengthA - curLengthC) == 1 && (movStates & 128) == 128 && aPos == 0 && cPos == 0) // a lift c
recursion(curLengthA, curLengthB == curLengthC ? curLengthA : curLengthB, curLengthA, movStates & 383, 0, bPos == 1 ? 2 : 0, 1);
if(Math.abs(curLengthA - curLengthC) == 1 && (movStates & 2) == 2 && aPos == 0 && cPos == 0) // c lift a
recursion(curLengthC, curLengthB == curLengthA ? curLengthC : curLengthB, curLengthC, movStates & 509, 1, bPos == 1 ? 2 : 0, 0);
if(Math.abs(curLengthB - curLengthC) == 1 && (movStates & 16) == 16 && bPos == 0 && cPos == 0) // b lift c
recursion(curLengthA == curLengthC ? curLengthB : curLengthA, curLengthB, curLengthB, movStates & 495, aPos == 1 ? 2 : 0, 0, 1);
if(Math.abs(curLengthB - curLengthC) == 1 && (movStates & 2) == 2 && bPos == 0 && cPos == 0) // c lift b
recursion(curLengthA == curLengthB ? curLengthC : curLengthA, curLengthC, curLengthC, movStates & 509, aPos == 1 ? 2 : 0, 1, 0); //throw
if(aPos + bPos + cPos == 1) { int lifting = 0;
if((movStates & 24) == 8)
lifting = 1;
if((movStates & 3) == 1)
lifting = 2; int throwed = 0;
if(bPos == 1)
throwed = 1;
if(cPos == 1)
throwed = 2; if(lifting == 0 && throwed == 1) { //a throw b
for(int i = 1; i <= this.aThr; i++) {
if(i + curLengthB != curLengthC)
recursion(curLengthA, curLengthB + i, curLengthC, movStates & 447, 0, 0, 0);
if(i - curLengthB != curLengthC)
recursion(curLengthA, curLengthB - i, curLengthC, movStates & 447, 0, 0, 0);
}
}
if(lifting == 0 && throwed == 2) { //a throw c
for(int i = 1; i <= this.aThr; i++) {
if(i + curLengthC != curLengthB)
recursion(curLengthA, curLengthB, curLengthC + i, movStates & 447, 0, 0, 0);
if(i - curLengthC != curLengthB)
recursion(curLengthA, curLengthB, curLengthC - i, movStates & 447, 0, 0, 0);
}
}
if(lifting == 1 && throwed == 0) { //b throw a
for(int i = 1; i <= this.bThr; i++) {
if(i + curLengthA != curLengthC)
recursion(curLengthA + i, curLengthB, curLengthC, movStates & 503, 0, 0, 0);
if(i - curLengthA != curLengthC)
recursion(curLengthA - i, curLengthB, curLengthC, movStates & 503, 0, 0, 0);
}
}
if(lifting == 1 && throwed == 2) { //b throw c
for(int i = 1; i <= this.bThr; i++) {
if(i + curLengthC != curLengthA)
recursion(curLengthA, curLengthB, curLengthC + i, movStates & 503, 0, 0, 0);
if(i - curLengthC != curLengthA)
recursion(curLengthA, curLengthB, curLengthC - i, movStates & 503, 0, 0, 0);
}
}
if(lifting == 2 && throwed == 0) { //c throw a
for(int i = 1; i <= this.cThr; i++) {
if(i + curLengthA != curLengthB)
recursion(curLengthA + i, curLengthB, curLengthC, movStates & 510, 0, 0, 0);
if(i - curLengthA != curLengthB)
recursion(curLengthA - i, curLengthB, curLengthC, movStates & 510, 0, 0, 0);
}
}
if(lifting == 2 && throwed == 1) { //c throw b
for(int i = 1; i <= this.cThr; i++) {
if(i + curLengthB != curLengthA)
recursion(curLengthA, curLengthB + i, curLengthC, movStates & 510, 0, 0, 0);
if(i - curLengthB != curLengthA)
recursion(curLengthA, curLengthB - i, curLengthC, movStates & 510, 0, 0, 0);
}
}
}
else if(aPos + bPos + cPos == 3) { int throwing = 0;
if(bPos == 0)
throwing = 1;
if(cPos == 0)
throwing = 2; if(throwing == 0) {
for(int i = 1; i <= this.aThr; i++) {
recursion(curLengthA, curLengthB + i, curLengthC + i, movStates & 447, 0, bPos - 1, cPos - 1);
recursion(curLengthA, curLengthB - i, curLengthC - i, movStates & 447, 0, bPos - 1, cPos - 1);
}
}
if(throwing == 1) {
for(int i = 1; i <= this.bThr; i++) {
recursion(curLengthA + i, curLengthB, curLengthC + i, movStates & 503, aPos - 1, 0, cPos - 1);
recursion(curLengthA - i, curLengthB, curLengthC - i, movStates & 503, aPos - 1, 0, cPos - 1);
}
}
if(throwing == 2) {
for(int i = 1; i <= this.cThr; i++) {
recursion(curLengthA + i, curLengthB + i, curLengthC, movStates & 510, aPos - 1, bPos - 1, 0);
recursion(curLengthA - i, curLengthB - i, curLengthC, movStates & 510, aPos - 1, bPos - 1, 0);
}
}
}
}
private int max_3(int a, int b, int c) {
if(a >= b && a >= c)
return a;
else if(b >= a && b >= c)
return b;
else
return c;
} }

这道题目是蓝桥杯官网练习系统的一道题目,我目前没有找到什么巧解来解决这道题目,大致上只是用暴力列举每一种情况。

当然这样做的坏处就是要面对极多的逻辑控制。我这代码最终也没有拿全分数,有3组测试数据跑出了时间限制。而且由于逻辑的控制过于复杂(对我来说),在不知道测试数据的情况下慢慢自己debug到现在已经是最好的情况了。其实继续下去也许能解决这个问题,但实在太恶心,等一些高人拿出比较精辟的想法吧。

lift and throw的更多相关文章

  1. 算法训练 Lift and Throw

    算法训练 Lift and Throw   时间限制:3.0s   内存限制:256.0MB      问题描述 给定一条标有整点(1, 2, 3, ...)的射线. 定义两个点之间的距离为其下标之差 ...

  2. Java实现 蓝桥杯 算法训练 Lift and Throw

    试题 算法训练 Lift and Throw 问题描述 给定一条标有整点(1, 2, 3, -)的射线. 定义两个点之间的距离为其下标之差的绝对值. Laharl, Etna, Flonne一开始在这 ...

  3. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...

  4. 总是有一个程序的bug没找到

     算法训练 Lift and Throw   时间限制:3.0s   内存限制:256.0MB      问题描述 给定一条标有整点(1, 2, 3, ...)的射线. 定义两个点之间的距离为其下标之 ...

  5. Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题

    C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  6. 浅谈Java的throw与throws

    转载:http://blog.csdn.net/luoweifu/article/details/10721543 我进行了一些加工,不是本人原创但比原博主要更完善~ 浅谈Java异常 以前虽然知道一 ...

  7. C++异常处理:try,catch,throw,finally的用法

    写在前面 所谓异常处理,即让一个程序运行时遇到自己无法处理的错误时抛出一个异常,希望调用者可以发现处理问题. 异常处理的基本思想是简化程序的错误代码,为程序键壮性提供一个标准检测机制. 也许我们已经使 ...

  8. java中的throw与throws的区别

    什么时运行时异常?什么是非运行时异常? 通俗的讲: 运行时异常:就是编译通过,运行时就崩了,比如数组越界. 非运行时异常:就是编译不通过,这时就得必须去处理了.不然就没法运行了. 全面的讲: Thro ...

  9. js 利用throw 写的一个小程序

    在下边的小程序中比较特殊的是使用isNaN()函数判断一个参数是不是数字, <!DOCTYPE html> <!DOCTYPE html> <html> <h ...

随机推荐

  1. loadView加载(变换成ScrollView)

    /**loadView加载,将系统的view变换成ScrollView*/ - (void)loadView{ [super loadView]; UIScrollView *mainScroll = ...

  2. 百度搜索--jquery

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. BZOJ 1304: [CQOI2009]叶子的染色

    1304: [CQOI2009]叶子的染色 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 566  Solved: 358[Submit][Statu ...

  4. LCT裸题泛做

    ①洞穴勘测 bzoj2049 题意:由若干个操作,每次加入/删除两点间的一条边,询问某两点是否连通.保证任意时刻图都是一个森林.(两点之间至多只有一条路径) 这就是个link+cut+find roo ...

  5. jquery两个滚动条样式

    jquery两个滚动条样式 点击下载

  6. 跟我学习Storm_Storm主要特点

    Storm拥有低延迟.高性能.分布式.可扩展.容错等特性,可以保证消息不丢失,消息处理严格有序.Storm的主要特点如下所示: 简单的编程模型.类似于MapReduce降低了并行批处理复杂性,Stor ...

  7. 你的C#代码是怎么跑起来的(二)

    接上篇:你的C#代码是怎么跑起来的(一) 通过上篇文章知道了EXE文件的结构,现在来看看双击后是怎样运行的: 双击文件后OS Loader加载PE文件并解析,在PE Optional Header里找 ...

  8. 20 seq 某个数到另外一个数之间的所有整数

    seq命令Shell内建命令 seq命令用于产生从某个数到另外一个数之间的所有整数. 语法 : seq [选项]... 尾数 seq [选项]... 首数 尾数 seq [选项]... 首数 增量 尾 ...

  9. 1121高性能MySQL之运行机制

    本文来自于拜读<高性能MySQL(第三版)>时的读书笔记作者:安明哲转载时请注明部分内容来自<高性能MySQL(第三版)> MySQL的逻辑构架 MySQL服务器逻辑架构 最上 ...

  10. URL参数GB2312和UTF-8编码 自动识别

    网上找的,以备后用. 直接上代码: public static string QueryStringDecode(string key) { HttpRequest Request = System. ...