论坛首页 Java企业应用论坛

网上没找到答案的逻辑推理题

浏览 17222 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-09-13  

/**
*
* @author q472732639
*
*/
public class Test {


public static void main(String [] args){
TeamObj a = new TeamObj(); //A队
TeamObj b = new TeamObj(); //B队
TeamObj c = new TeamObj(); //C队
int roundNum = 1; //回合数
/*
* 下面的纯粹就是按照题意所写的判断 不精湛 粗略的理解为a是必须赢数多.但不一定不输,
* b必须是输数少,但不一定去赢,c是积分一定要高,但一定要让A,B两组积分低的情况下不影响战绩..全是废话
*/
for(int i = 0 ; i < roundNum ; i ++){
if(a.getWinNum() <= b.getWinNum()
|| a.getWinNum() <= c.getWinNum()){
a.setWinNum(a.getWinNum() + 1);
a.setMin(a.getMin() + 2);
if(b.getLoseNum() - c.getLoseNum() > 1){
b.setLoseNum(b.getLoseNum() + 1);
}else{
c.setLoseNum(c.getLoseNum() + 1);
}
}else if(b.getLoseNum() >= c.getLoseNum()){
b.setWinNum(b.getWinNum() + 1);
b.setMin(b.getMin() + 2);
if(a.getWinNum() - b.getWinNum() > 1){
a.setLoseNum(a.getLoseNum() + 1);
}else{
c.setLoseNum(c.getLoseNum() + 1);
}
}else if(b.getLoseNum() >= a.getLoseNum()){
b.setWinNum(b.getWinNum() + 1);
b.setMin(b.getMin() + 2);
a.setLoseNum(c.getLoseNum() + 1);
}else if(c.getMin() <= a.getMin() || c.getMin() <= b.getMin()){
c.setWinNum(c.getWinNum() + 1);
c.setMin(c.getMin() + 2);
if(a.getWinNum() - c.getWinNum() > 1){
a.setLoseNum(a.getLoseNum() + 1);
}else if(b.getLoseNum() - c.getLoseNum() > 1){
b.setLoseNum(b.getLoseNum() + 1);
}else{
c.setDrawNum(b.getDrawNum() + 1);
c.setMin(c.getMin() + 1);
if(b.getMin() > a.getMin()){
a.setMin(a.getMin() + 1);
a.setDrawNum(a.getDrawNum() + 1);
}else{
b.setMin(b.getMin() + 1);
b.setDrawNum(b.getDrawNum() + 1);
}
}
}
if((a.getWinNum() > c.getWinNum() && a.getWinNum() > b.getWinNum())
&& (b.getLoseNum() < a.getLoseNum() && b.getLoseNum() < c.getLoseNum() )
&& (c.getMin() > a.getMin() && c.getMin() > b.getMin()) ){
System.out.println("a win :" + a.getWinNum() + "  lose :" + a.getLoseNum() + "  drawnum :" + a.getDrawNum() + "  min :" + a.getMin());
System.out.println("b win :" + b.getWinNum() + "  lose :" + b.getLoseNum() + "  drawnum :" + b.getDrawNum() + "  min :" + b.getMin());
System.out.println("c win :" + c.getWinNum() + "  lose :" + c.getLoseNum() + "  drawnum :" + c.getDrawNum() + "  min :" + c.getMin());
System.out.println("roundNum : " + roundNum);
break;
}else{
System.out.println("a win :" + a.getWinNum() + "  lose :" + a.getLoseNum() + "  drawnum :" + a.getDrawNum() + "  min :" + a.getMin());
System.out.println("b win :" + b.getWinNum() + "  lose :" + b.getLoseNum() + "  drawnum :" + b.getDrawNum() + "  min :" + b.getMin());
System.out.println("c win :" + c.getWinNum() + "  lose :" + c.getLoseNum() + "  drawnum :" + c.getDrawNum() + "  min :" + c.getMin());
System.out.println("-------------------------------------------------------");
roundNum ++ ;
}
}
}

}


那个队伍对象就不写了
楼上说的对先用方程式找好数据之间的关系.然后列出来.在解出来就不难了..我这小白代码只是看下..
0 请登录后投票
   发表时间:2009-09-13  
package filter;

public class TeamObj {

	private int min;
	
	private int winNum;
	
	private int loseNum;
	
	private int drawNum;

	public int getMin() {
		return min;
	}

	public void setMin(int min) {
		this.min = min;
	}

	public int getWinNum() {
		return winNum;
	}

	public void setWinNum(int winNum) {
		this.winNum = winNum;
	}

	public int getLoseNum() {
		return loseNum;
	}

	public void setLoseNum(int loseNum) {
		this.loseNum = loseNum;
	}

	public int getDrawNum() {
		return drawNum;
	}

	public void setDrawNum(int drawNum) {
		this.drawNum = drawNum;
	}
	
}


重新发...
0 请登录后投票
   发表时间:2009-09-13  
/**
 * 
 * @author q472732639
 *
 */
public class Test {

	public static void main(String [] args){
		TeamObj a = new TeamObj();		//A队
		TeamObj b = new TeamObj();		//B队
		TeamObj c = new TeamObj();		//C队
		int roundNum = 1;	//回合数
		/*
		 * 下面的纯粹就是按照题意所写的判断 不精湛 粗略的理解为a是必须赢数多.但不一定不输,
		 * b必须是输数少,但不一定去赢,c是积分一定要高,但一定要让A,B两组积分低的情况下不影响战绩..全是废话
		*/
		for(int i = 0 ; i < roundNum ; i ++){
			if(a.getWinNum() <= b.getWinNum() 
					|| a.getWinNum() <= c.getWinNum()){
				a.setWinNum(a.getWinNum() + 1);
				a.setMin(a.getMin() + 2);
				if(b.getLoseNum() - c.getLoseNum() > 1){
					b.setLoseNum(b.getLoseNum() + 1);
				}else{
					c.setLoseNum(c.getLoseNum() + 1);
				}
			}else if(b.getLoseNum() >= c.getLoseNum()){
				b.setWinNum(b.getWinNum() + 1);
				b.setMin(b.getMin() + 2);
				if(a.getWinNum() - b.getWinNum() > 1){
					a.setLoseNum(a.getLoseNum() + 1);
				}else{
					c.setLoseNum(c.getLoseNum() + 1);
				}
			}else if(b.getLoseNum() >= a.getLoseNum()){
				b.setWinNum(b.getWinNum() + 1);
				b.setMin(b.getMin() + 2);
				a.setLoseNum(c.getLoseNum() + 1);
			}else if(c.getMin() <= a.getMin() || c.getMin() <= b.getMin()){
				c.setWinNum(c.getWinNum() + 1);
				c.setMin(c.getMin() + 2);
				if(a.getWinNum() - c.getWinNum() > 1){
					a.setLoseNum(a.getLoseNum() + 1);
				}else if(b.getLoseNum() - c.getLoseNum() > 1){
					b.setLoseNum(b.getLoseNum() + 1);
				}else{
					c.setDrawNum(b.getDrawNum() + 1);
					c.setMin(c.getMin() + 1);
					if(b.getMin() > a.getMin()){
						a.setMin(a.getMin() + 1);
						a.setDrawNum(a.getDrawNum() + 1);
					}else{
						b.setMin(b.getMin() + 1);
						b.setDrawNum(b.getDrawNum() + 1);
					}
				}
			}
			if((a.getWinNum() > c.getWinNum() && a.getWinNum() > b.getWinNum()) 
					&& (b.getLoseNum() < a.getLoseNum() && b.getLoseNum() < c.getLoseNum() ) 
						&& (c.getMin() > a.getMin() && c.getMin() > b.getMin()) ){
				System.out.println("a win :" + a.getWinNum() + "  lose :" + a.getLoseNum() + "  drawnum :" + a.getDrawNum() + "  min :" + a.getMin());
				System.out.println("b win :" + b.getWinNum() + "  lose :" + b.getLoseNum() + "  drawnum :" + b.getDrawNum() + "  min :" + b.getMin());
				System.out.println("c win :" + c.getWinNum() + "  lose :" + c.getLoseNum() + "  drawnum :" + c.getDrawNum() + "  min :" + c.getMin());
				System.out.println("roundNum : " + roundNum);
				break;
			}else{
				System.out.println("a win :" + a.getWinNum() + "  lose :" + a.getLoseNum() + "  drawnum :" + a.getDrawNum() + "  min :" + a.getMin());
				System.out.println("b win :" + b.getWinNum() + "  lose :" + b.getLoseNum() + "  drawnum :" + b.getDrawNum() + "  min :" + b.getMin());
				System.out.println("c win :" + c.getWinNum() + "  lose :" + c.getLoseNum() + "  drawnum :" + c.getDrawNum() + "  min :" + c.getMin());
				System.out.println("-------------------------------------------------------");
				roundNum ++ ;
			}
		}
	}
	
}
0 请登录后投票
   发表时间:2009-09-13  
啊lei lei!..审题没审明白..
0 请登录后投票
   发表时间:2009-09-15  
bookong 写道
monsterjiao 写道
如果喜欢足球比赛并关注得的话,心算一下应该就能出来吧:
一个简单的例子就能证明丙有夺冠的可能:
队伍  胜   负   平    总积分
甲    3    5   0      9
乙    1    1   6      8  
丙    2    2   4      10
此题解法:
先证明丙会超过乙的积分:乙比并少输,但是输球是0分,而胜是3分,平是1分,那么丙只要将比乙多输的一场放到胜场上,也就是说丙比乙多赢也多输了一场,而平局自然就是乙比丙多了两场,算下来3-2=1,丙超过了乙的积分。
然后证明丙会超过甲的积分:甲比丙多赢一场,光看胜场是多了3分,而甲比并多输的场是可以无限多加入为N吧(反正题目中又没有说三队之前是进行了多少场比较),那么丙的平局的场次自然就比甲多出N-1,(N-1)*1>3的情况很容易出现吧。
希望能帮助到你


对不起,我真没看懂你的例子,我有两个疑问:
1、看看乙吧,1×3+6在什么情况下能等于8?
2、甲负了5场,乙和丙胜利加起来1+2=3,那两场是跟谁?


嘿嘿,不好意思;是我的问题;当时重在解题思路了,再说也是思路不够缜密,例子举错了~但也只是错例子而已;谢谢指出。
0 请登录后投票
   发表时间:2009-09-15  
标准答案其实是这样的:
甲乙两队打平,所以一个“得意洋洋”一个“反唇相讥”。
丙队是垫底的,所以丙队发言“一声不吭”。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics