C++ CodeForces小马和Tirek勋爵从我的电脑获得不同的输出
我试图解决这个问题。 小马和泰瑞克勋爵 这是我的解决方案C++ CodeForces小马和Tirek勋爵从我的电脑获得不同的输出,c++,C++,我试图解决这个问题。 小马和泰瑞克勋爵 这是我的解决方案 /* HahaTTpro Little Pony and Lord Tirek http://codeforces.com/problemset/problem/453/E */ #include <iostream> using namespace std; struct pony { long startMana; long regenMana; long maxMana; lon
/*
HahaTTpro
Little Pony and Lord Tirek
http://codeforces.com/problemset/problem/453/E
*/
#include <iostream>
using namespace std;
struct pony
{
long startMana;
long regenMana;
long maxMana;
long curMana;
};
class Problem
{
private:
pony *Pony;
long totalPonies;
long time;
long totalMana;
void killPony();
void regen(long newtime);
long drain(long target);
public:
~Problem();
void inputPony();
int instruction(long t, long r, long l);
int getTotalPony(){
return totalPonies;
};
};
void Problem::inputPony()
{
cin >> totalPonies;
Pony = new pony[totalPonies];
for (long i = 0; i < totalPonies; i++)
{
cin >> Pony[i].startMana;
cin >> Pony[i].maxMana;
cin >> Pony[i].regenMana;
Pony[i].curMana = Pony[i].startMana;
}
}
void ::Problem::killPony()
{
delete[]Pony;
}
Problem::~Problem()
{
killPony();
}
void Problem::regen(long newtime)
{
long dentatime = newtime - time;
for (long i = 0; i < totalPonies; i++)
{
Pony[i].curMana = Pony[i].curMana + Pony[i].regenMana*dentatime;
if (Pony[i].curMana > Pony[i].maxMana) Pony[i].curMana = Pony[i].maxMana;
}
time = newtime;
}
long Problem::drain(long target)
{
long result = 0;
result = Pony[target].curMana;
Pony[target].curMana = 0;
return result;
}
int Problem::instruction(long t, long l, long r)
{
regen(t);
l--;
r--;
int res=0;
for (long i = l; i <= r; i++)
{
res=res + drain(i);
}
return res;
}
int main()
{
Problem LittlePoNy;
LittlePoNy.inputPony();
long m;
int t, l, r;
cin >> m;
int *Result;
Result = new int[m];
for (long i = 0; i < m; i++)
{
cin >> t >> l >> r;
Result[i] = LittlePoNy.instruction(t, l, r) ;
}
for (int i = 0; i < m; i++)
{
cout << Result[i] << endl;
}
return 0;
}
//wtf ?
输出
25
58
但在判决时,它被判有罪
35
58
如何解决此问题?可能是成员变量“time”在使用前未初始化。步骤1:启动调试器。是的。谢谢我加上时间=0,判断运行正常,给出正确的输出。。。直到超过时间限制的试验12:D
35
58