2011-11-21 33 views
-3

我试图刷新我的算法技巧并遇到此问题。这里所说:http://opc.iarcs.org.in/index.php/problems/LEADGAME无法理解要求

我的代码是:

#include <iostream> 
#include <cmath> 

using namespace std; 

int main(int argc, char* argv[]) 
{ 
    int count; 
    cin >> count; 

    int winningP = 1; // winning player 
    int lead = 0; // lead 

    for (int i=0; i < count; i++) 
    { 
     int scoreA, scoreB = 0; 
     cin >> scoreA >> scoreB; 

     int l; 
     if (scoreA > scoreB) 
      l = scoreA - scoreB; 
     else 
      l = scoreB - scoreA; 

     if (l > lead) // greater lead than what's been processed 
     { 
      lead = l; 
      winningP = scoreA > scoreB ? 1 : 2; 
     } 
    } 

    cout << winningP << " " << lead; 

    return 0; 
} 

然而,在网站上,当我提出我的代码进行评估,它打印出我的程序是给错误的答案。我在这里做错了什么?样本输入和输出已被验证。

+0

你有没有除了这个例子之外还尝试过其他的输入和输出吗你确定输出的格式正确吗? – Bart

+2

这可能像最后一个缺失的换行符一样简单? –

+0

我确实尝试了其他输入和输出,并根据它的行为方式得到正确答案,除非我错误地解释了问题本身。至于缺失换行符,我尝试添加,但无济于事。 – Ishbir

回答

1

您正在解决一个不同的问题。你会发现以最大比率(以及该比率)赢得任何一轮的玩家。在问题中,回合的得分是累积的,所以如果例如,玩家1在第一轮中获得58并在第二轮中丢失45,在玩完两轮后,玩家1依然领先13.

+0

哦,所以分数越来越高。没有看到这一点。谢谢! – Ishbir