0
我最近參加了Codesprint2。我無法將解決方案提交給以下問題。 http://www.spoj.pl/problems/COINTOSS/ (我已經發布的鏈接問題的陳述在SPOJ因爲codesprint鏈接需要登錄)爪哇 - codesprint2編程競賽答案
我檢查了成功的解決方案之一,(網址:http://pastebin.com/uQhNh9Rc)和使用的邏輯是完全一樣的礦,但我仍然得到「錯誤答案」
,我會很感激,如果有人可以告訴我,我取得了什麼樣的錯誤,因爲我無法找到它。謝謝。
我的代碼:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
public class Solution
{
static double solve(int n, int m)
{
if(m==n)
return 0;
if(m==0)
return (Math.pow(2, n+1) - 2);
else
{
double res = 1 + (Double)( solve(n, m+1) + solve(n, 0))/2;
return res;
}
}
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n, m;
int t = Integer.parseInt(br.readLine());
StringTokenizer tok;
String s;
for(int T=0; T<t; T++)
{
s = br.readLine();
tok = new StringTokenizer(s);
n = Integer.parseInt(tok.nextToken());
m = Integer.parseInt(tok.nextToken());
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
System.out.println(df.format (solve(n, m)));
}
}
}
原始問題語句的約束0 <= M <= N – arya 2012-01-10 05:56:31