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. IOS第四课——Autolayout_View

    这节课,我们要学习MVC.Selector.Access Control.Extension.Auto Layout.Delegate-Protocol.Custom View. Auto Layou ...

  2. Netty Client重连实现

    from:http://itindex.net/detail/54161-netty-client 当我们用Netty实现一个TCP client时,我们当然希望当连接断掉的时候Netty能够自动重连 ...

  3. 浅谈python web框架中的orm设计

    看了一下廖雪峰的那个web框架,其实就是封装了web.py,请求使用异步并将aiomysql做为MySQL数据库提供了异步IO的驱动,前端部分则整合了jinja.其中最难的应该是orm部分了. 下面是 ...

  4. oracle编程总结

    1,SEQUENCE的使用 问题:在MSSQL中,我们可以通过设置自增长来作为主键,但是oracle里面没有这个 解决方案:使用SEQUENCE来实现,具体步骤如下 (1)首先建立一个序列(就是每次查 ...

  5. 夯实基础之php学习-2提高篇

    1,Jpgraph, 详见Php图形化jpgraph 2,文件系统 文件的操作步骤:打开文件->操作文件->关闭文件 打开文件fopen(filename,mode) 关闭文件fclose ...

  6. MySQL触发器如何正确使用

    MySQL触发器如何正确使用 2010-05-18 15:58 佚名 博客园 字号:T | T 我们今天主要向大家介绍的是MySQL触发器进行正确使用,其中包括对MySQL触发器发器的语句创建,触发时 ...

  7. MySQL数据库集群进行正确配置步骤

    MySQL数据库集群进行正确配置步骤 2010-06-09 10:47 arrowcat 博客园 字号:T | T 我们今天是要和大家一起分享的是对MySQL数据库集群进行正确配置,我前两天在相关网站 ...

  8. [转]RabbitMQ消息队列在PHP下的应用

    FROM : http://www.cnblogs.com/phpinfo/p/4104551.html 参考资料: http://www.yuansir-web.com/tag/rabbitmq/ ...

  9. C#并行编程中的Parallel.Invoke

    一.基础知识 并行编程:并行编程是指软件开发的代码,它能在同一时间执行多个计算任务,提高执行效率和性能一种编程方式,属于多线程编程范畴.所以我们在设计过程中一般会将很多任务划分成若干个互相独立子任务, ...

  10. JAVA对象和XML文档、原来他们之间还有这一出

    最近项目开发中遇到一个问题,访问接口不再通过url地址请求的方式,而是 通过socket发送xml格式的报文到指定服务器来进行信息的统一认证.. 因此组装xml格式的报文字符串以及解析服务器返回的xm ...