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. poj2676 Sudoku

    Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17953   Accepted: 8688   Special ...

  2. android java.io.IOException: open failed: EBUSY (Device or resource busy)

    今天遇到一个奇怪的问题, 测试在程序的下载界面,下载一个文件第一次下载成功,删除后再下载结果下载报错, 程序:file.createNewFile(); 报错:java.io.IOException: ...

  3. java list

    List:元素是有序的(怎么存的就怎么取出来,顺序不会乱),元素可以重复(角标1上有个3,角标2上也可以有个3)因为该集合体系有索引 ArrayList:底层的数据结构使用的是数组结构(数组长度是可变 ...

  4. HOJ 2713 Matrix1

    Matrix1 My Tags   (Edit)   Source : Classical Problem   Time limit : 5 sec   Memory limit : 64 M Sub ...

  5. Frequently Asked Questions - P-thresholds

    Source: http://mindhive.mit.edu/book/export/html 1. What is the multiple-comparison problem? What is ...

  6. CSS3中的Rem值与Px之间的换算

    bootstrap默认 html{font-size: 10px;} rem是一个相对大小的值,它相对于根元素<html>, 比如假设,我们设置html的字体大小的值为html{font- ...

  7. 【转】$_POST 与 php://input的区别分析

    $data = file_get_contents("php://input"); php://input 是个可以访问请求的原始数据的只读流. POST 请求的情况下,最好使用 ...

  8. Python快速教程目录(转)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 怎么能快速地掌握Python?这是和朋友闲聊时谈起的问题. Python包含的内容 ...

  9. scala 学习笔记(07) 一等公民的函数

    在scala中一切皆对象,一切皆函数,函数跟Int,String.Class等其它类型是处于同等的地位,换句话说,使用函数跟使用普通的类型一样,没什么区别,因此: 1.函数可以赋值给变量,可以当参数传 ...

  10. java:使用匿名类直接new接口

    java中的匿名类有一个倍儿神奇的用法,见下面代码示例: package contract; public interface ISay { void sayHello(); } 上面是一个简单的接口 ...