#include<iostream>#include<vector>using namespace std;int main(void){ //freopen("in.txt", "r", stdin); int np, ng;//總人數, 每組人數 cin >> np >> ng; vector<int> wgt(np), list(np), rank(np);//分別為分數, pk的人員編號, 排名 for (int i = 0; i < np; i++) cin >> wgt[i]; for (int i = 0; i < np; i++) cin >> list[i]; while (list.size() > 1)//pk人數=1跳出循環 { int now_rank = list.size() / ng + 1;//目前的排名 if (list.size() % ng > 0)//有多余的要+1 now_rank++; vector<int> pro;//存儲晉級的人員 int i = 0; while (i < list.size()) { int max = -1; int m_id; for (int j = 0; j < ng && i < list.size(); j++, i++)//找出晉級人員 { rank[list[i]] = now_rank;//排名賦值 if (wgt[list[i]] > max) { max = wgt[list[i]]; m_id = list[i]; } } pro.push_back(m_id); } list = pro; } rank[list[0]] = 1;//第一名 for (int i = 0; i < np; i++) { if (i == 0) cout << rank[i]; else cout << ' ' << rank[i]; } cout << endl; return 0;}參考自:http://blog.csdn.net/yangsongtao1991/article/details/43417363
新聞熱點
疑難解答