我正在努力提高我的算法技能,并遇到了这个问题。这是: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 :(得分:1)
您正在解决另一个问题。你会发现以最大的差距赢得任何回合的球员(和那个边际)。在这个问题中,轮次的得分是累积的,所以如果在例子中,球员1赢得第一轮58并且输掉第二轮45,在两轮之后,球员1仍然领先13。