我试着解决这个问题。 小小马和Tirek勋爵 http://codeforces.com/contest/453/problem/E
这是我的解决方案
/*
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 ?
和判决:http://codeforces.com/contest/453/submission/7334245 在我的电脑上 输入
5
0 10 1
0 12 1
0 20 1
0 12 1
0 10 1
2
5 1 5
19 1 5
输出
25
58
但是在判决中,它得到了
35
58
我该如何解决这个问题?
答案 0 :(得分:0)
可能是会员变量&#34; time&#34;在使用之前未初始化。