以下附上我的程式碼:
其中有標斜線,大約65行左右有試著印出每一回答結束後的戰力,應變力還有下一回合的順序
但我印出的數字與答案都不吻合
有試著改s和t為float,結果答案差更多
想知道問題出在哪裡
謝謝回答
#include<iostream>
using namespace std;
#include<vector>
struct player{
long long int s;
long long int t;
int lose;
};
int main() {
int n, m;
cin>>n>>m;
struct player p[n+1];
for(int i = 1; i <= n; i++) {
p[i].lose = 0;
cin>>p[i].s;
}
for(int i = 1; i <= n; i++)
cin>>p[i].t;
vector<int> pr;
for(int i = 0; i < n; i++) {
int temp;
cin>>temp;
pr.push_back(temp);
}
vector<int> w, l;
int num = n;
while(num > 1) {
for(int i = 0; i < n; i+=2) {
int a = p[pr[i]].s, b = p[pr[i]].t, c = p[pr[i+1]].s, d = p[pr[i+1]].t;
if(a*b >= c*d) {
p[pr[i]].s = a+c*d/2/b;
p[pr[i]].t = b+c*d/2/a;
p[pr[i+1]].s = c+c/2;
p[pr[i+1]].t = d+d/2;
p[pr[i+1]].lose++;
if(p[pr[i+1]].lose >= m)
num--;
else
l.push_back(pr[i+1]);
w.push_back(pr[i]);
}
else{
p[pr[i+1]].s = c+a*b/2/d;
p[pr[i+1]].t = d+a*b/2/c;
p[pr[i+1]].s = a+a/2;
p[pr[i+1]].t = b+b/2;
p[pr[i]].lose++;
if(p[pr[i]].lose >= m)
num--;
else
l.push_back(pr[i]);
w.push_back(pr[i+1]);
}
}
if(n%2 != 0)
w.push_back(pr[n-1]);
pr.clear();
pr.insert(pr.end(), w.begin(), w.end());
pr.insert(pr.end(), l.begin(), l.end());
w.clear();
l.clear();
n = num;
/* for(int i = 0; i < n; i++)
cout<<pr[i]<<" ";
cout<<endl;
for(int i = 1; i <= n; i++)
cout<<p[i].s<<" ";
cout<<endl;
for(int i = 1; i <= n; i++)
cout<<p[i].t<<" ";
cout<<endl;
for(int i = 1; i <= n; i++)
cout<<p[i].lose<<" ";
cout<<endl<<"-----"<<endl;*/
}
cout<<pr[0];
return 0;
}