Feedback
2008-12-12 23:31 |
直接使用Mathematica 一步就算出來,不就是一個3*3矩陣么?哈哈
樓主很喜歡動手,贊賞。
Happy your weekend toooooo!
回復 更多評論
2008-12-12 23:48 |
C的年齡段兩倍是A與B兩個年齡的差數?
看了半天也沒理解他意思:年齡段和年齡是兩個概念!題目有誤還是字打錯了?
回復 更多評論
2008-12-13 00:01 |
另外,程序也寫錯了
應該是:
b = 10 * c;
a = 12 * c;
或者
b = 10 * c;
a = 8 * c;
你之前那樣寫就直接把A的年齡人為定義地比B大了。而實際上題目沒這么說。
真正的解答肯定不復雜,但是也沒你寫得那么簡單?;蛘呶疫@么說——你的解答還是不夠嚴謹,就這樣交上去人家應該不會給獎品的 :D
回復 更多評論
2008-12-13 00:19 |
@koven
的確是手誤了,多謝指出,現已經改正。
回復 更多評論
2008-12-13 00:46 |
我寫了一段很爛的代碼,得到相當多的答案。我覺得誰有時間還可以優化一下:
public class Main
{
static double x, y;
private static double personA(){
return 10*x+y;
}
private static double personB(){
return 10*y+x;
}
private static double personC(){
return personB()/10;
}
public static boolean formel1(){
return 2*personC() == personA()-personB();
}
public static boolean formel2(){
return 2*personC() == personB()-personA();
}
private static void getResult(boolean formel){
for (x = 1; x < 9; x ++) {
for (y = 1; y < 9; y++) {
if (formel){
System.out.println("get result:");
System.out.println("A=" + personA());
System.out.println("B=" + personB());
System.out.println("C=" + personC());
}
}
}
}
public static void main(String[] args) {
getResult(formel1());
getResult(formel2());
}
}
回復 更多評論
2008-12-13 00:51 |
sorry 忘記說了:
x, y代表個位和十位數
formel1 和 formel2 分別代表 A比B大 或者 B比A大的情況
回復 更多評論
2008-12-13 02:49 |
formel2算不出答案,所以只用formel1。所以程序這樣寫才正確。但是代碼寫的還是太屎,大家將就點看~~ :p
程序比較長,是因為把心算部分也寫在程序里了。
public class Test
{
static double x, y;
private static double personA(){
return 10*x+y;
}
private static double personB(){
return 10*y+x;
}
private static double personC(){
return personB()/10;
}
public static boolean formel1(){
return 2*personC() == personA()-personB();
}
public static boolean formel2(){
return 2*personC() == personB()-personA();
}
private static void getResult(){
for (x = 1; x < 9; x ++) {
for (y = 1; y < 9; y++) {
if (formel1()){
System.out.println("get result:");
System.out.println("A=" + personA());
System.out.println("B=" + personB());
System.out.println("C=" + personC());
}
}
}
}
public static void main(String[] args) {
getResult();
}
}
回復 更多評論
2008-12-13 03:14 |
完美般!嘿嘿~~
public class Test
{
//個位和十位
static int x, y;
private static double personA(){
return 10*x+y;
}
private static double personB(){
return 10*y+x;
}
private static double personC(){
return personB()/10;
}
//是否滿足條件:C的年齡兩倍是A與B 兩個年齡的差數
public static boolean condition(){
boolean condition= (2*personC() == personA()-personB()) || (2*personC() == personB()-personA()) ;
return condition;
}
private static void getResult(){
for (x = 1; x < 9; x ++) {
for (y = 1; y < 9; y++) {
if (condition()){
System.out.println("Result:");
System.out.println("A=" + personA());
System.out.println("B=" + personB());
System.out.println("C=" + personC());
}
}
}
}
public static void main(String[] args) {
getResult();
}
回復 更多評論
2008-12-13 03:25 |
如果還要優化,還可以把personA()和personB()都定義成int型的,然后在personC()里強制 return (double)personB()/10;這樣結果就會是:
Result:
A=54
B=45
C=4.5
而不會成為:
Result:
A=54.0
B=45.0
C=4.5
還節約的內存。
回復 更多評論
2008-12-13 10:41 |
將A的年齡數字的位置對調一下,就是B的年齡;C的年齡兩倍是A與B
兩個年齡的差數;而B的年齡是C的10倍
將A的年齡數字的位置對調一下,就是B的年齡 =>A與B的年齡差是9的倍數。
C的兩倍是這個差數=>C的年齡是4.5的倍數,=>B的年齡是45的倍數=>
B=45或90
=>C=4.5或9
=>A-B=9或18
這種題目還要寫程序算,而且程序還是沒質量的暴力枚舉?;璧?。
什么團隊啊。
回復 更多評論
2008-12-13 10:47 |
@koven
恩很符合java編程理念
回復 更多評論
2008-12-13 11:20 |
@koven
呵呵,非常感謝不斷改進,程序員需要這種任勁來不斷提升自已。
@sunnycare
你的解法不錯,好的團隊應該虛心學習。
回復 更多評論
2008-12-13 11:22 |
我想到的是解方程,哈哈?。?
然后突然發現,那些數學知識已經忘的差不多了
回復 更多評論
2008-12-13 13:20 |
@x.matthew
呵呵,智力題應該盡量用腦算,寫程序就沒意思了。
你們只出了一道智力題么?
回復 更多評論
2008-12-13 15:17 |
就是考算法和數據結構的智力題
回復 更多評論
2008-12-13 16:19 |
程序員可以思考出答案,也可以算出答案,沒什么不對的,學習
回復 更多評論
2008-12-13 18:27 |
@sunnycare
"=>A與B的年齡差是9的倍數。"
如果這個規律是正確的,那屬于很復雜的心算,或者說是復雜規律的總結,當中跳掉很多思維過程。
"=>B=45或90
=>C=4.5或9
=>A-B=9或18"
可惜答案錯誤。
回復 更多評論
2008-12-13 21:00 |
@koven
一個數除以9的余數,等于該數各位數字和除以9的余數。
由于A和B的各位數字和相等,所以他們的差是9的倍數。
濾掉B=90的情況。為什么濾掉,因為進一步求出的A,B會有矛盾。
這道題目年齡會有小數,本身就不合理。
另外一組答案,
5.4,4.5,0.45
如果年齡允許的小數位更多,那么答案可能更多。
我只想提供一種思路。哈哈
回復 更多評論
2008-12-14 12:09 |
難道我機器有毛病??還是論壇哪一方面出問題啦?在首頁怎么還是顯示“年齡段”呀?
回復 更多評論
2008-12-14 12:34 |
//感覺有時候把數學方法寫成程序不知道行不行,幫忙指點一下
package org.shz.counter;
public class Calculation {
public static void main(String[] args) {
for (double i = 0; i < 10; i++) {
for (double j = 0; j < 10; j++) {
double A = 10 * i + j;
double B = 10 * j + i;
double C = B / 10;
if (!(A == 0 && B == 0 && C == 0)) {
if (A - B == 2 * C) {
System.out.println("A:" + A);
System.out.println("B:" + B);
System.out.println("C:" + C);
}
}
}
}
System.out.println("OK");
}
}
回復 更多評論
2008-12-14 14:44 |
由題中的條件10C=B ,,隱含的條件0<B<=100 則有0<C<10,用C的年齡計數循環,大大減少循環次數,
回復 更多評論
2008-12-14 18:26 |
用java編寫面向過程的程序還不如不用java呢。
回復 更多評論
2008-12-14 23:36 |
@咕嘎
是我忘修改摘要所致,太粗心了。
回復 更多評論
2008-12-16 10:28 |
這是一道程序敘述題,哪里是智力題?列方程就行,基本上沒什么邏輯判斷
回復 更多評論
2008-12-16 10:31 |
@徐堯
是智力題,只是程序員用的這種解題方式覺是變成了一個結果的枚舉了。
sunnycare 的解題思路你可以看一下。
回復 更多評論