7-20 奧運排行榜 (25分)(c++ STL)
我開始水題了(我好像一直都在水題)
這個部落格裡有幾份測試資料
https://blog.csdn.net/u012860063/article/details/41407809?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int INF = 65535;
const int MAXNUM = 1e5 + 5;
typedef struct info
{
int id;
int Gold_medals;
int Number_of_medals;
int Population;
//GP——Gold_medals/Population
double GP;
//NP——Number_of_medals/Population
double NP;
}info;
info method[4][MAXNUM];
bool cmp1(info a, info b)
{
if (a.Gold_medals == b.Gold_medals) return a.id < b.id;
return a.Gold_medals > b.Gold_medals;
}
bool cmp2(info a, info b)
{
if (a.Number_of_medals == b.Number_of_medals) return a.id < b.id;
return a.Number_of_medals > b.Number_of_medals;
}
bool cmp3(info a, info b)
{
return a.GP > b.GP;
}
bool cmp4(info a, info b)
{
return a.NP > b.NP;
}
int main()
{
//ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 4; j++)
method[j][i].id = i;
scanf("%d %d %d", &method[0][i].Gold_medals, &method[0][i].Number_of_medals, &method[0][i].Population);
method[0][i].GP = 1.0 * method[0][i].Gold_medals / method[0][i].Population;
method[0][i].NP = 1.0 * method[0][i].Number_of_medals / method[0][i].Population;
for (int j = 1; j < 4; j++)
{
method[j][i].Gold_medals = method[0][i].Gold_medals;
method[j][i].Number_of_medals = method[0][i].Number_of_medals;
method[j][i].Population = method[0][i].Population;
method[j][i].GP = 1.0 * method[j][i].Gold_medals / method[j][i].Population;
method[j][i].NP = 1.0 * method[j][i].Number_of_medals / method[j][i].Population;
}
}
sort(method[0], method[0] + n, cmp1);
sort(method[1], method[1] + n, cmp2);
sort(method[2], method[2] + n, cmp3);
sort(method[3], method[3] + n, cmp4);
if (m > n) m = n;
for (int i = 0; i < m; i++)
{
if (i) cout << ' ';
int country, mtd, ans1 = INF, ans2 = 0;
cin >> country;
for (mtd = 0; mtd < 4; mtd++)
{
for (int j = 0; j < n; j++)
{
if (method[mtd][j].id == country)
{
//有兩個測試點在這
//排名相同,在查詢的時候 儘量往前排
if (mtd == 0)
{
while (j >= 1 && method[mtd][j].Gold_medals == method[mtd][j-1].Gold_medals) j--;
}
else if (mtd == 1)
{
while (j >= 1 && method[mtd][j].Number_of_medals == method[mtd][j-1].Number_of_medals) j--;
}
else if (mtd == 2)
{
while (j >= 1 && method[mtd][j].GP == method[mtd][j-1].GP) j--;
}
else if (mtd == 3)
{
while (j >= 1 && method[mtd][j].NP == method[mtd][j-1].NP) j--;
}
if (ans1 > j)
{
ans1 = j;
ans2 = mtd;
}
break;
}
}
}
printf("%d:%d", ans1 + 1, ans2 + 1);
}
system("pause");
return 0;
}
相關文章
- C++ STL listC++
- C++ STL stackC++
- C++ STL -- vectorC++
- C++ STL -- listC++
- C++ STL -- HashTableC++
- 【C++ STL】Set用法C++
- C++ 模板與STLC++
- C++ STL deque容器C++
- C++ stl容器詳解C++
- C++ STL之迭代器C++
- C++ STL迭代器(iterator)C++
- C++ STL學習——vectorC++
- C++ STL容器總結C++
- C++ STL簡介 (轉)C++
- C++ STL stack容器——棧C++
- C++實踐:STL容器reserveC++
- [C++] STL相關面試題C++面試題
- C++ STL學習之stack。C++
- C++ STL list連結串列C++
- 【C++ STL】queue和priority_queueC++
- C++ STL演算法總結C++演算法
- C++基礎::STL中的定理C++
- 談談 C++ STL 中的迭代器C++
- (C++)STL資料存取效率問題C++
- C++ 學習筆記之——STL 庫 queueC++筆記
- Android NDK開發之旅26 C++ STLAndroidC++
- C++ 學習筆記之 STL 佇列C++筆記佇列
- c++ STL Algorithm簡單總結備忘C++Go
- boolan c++ stl 第四周筆記C++筆記
- c++標準程式庫:STL容器之mapC++
- C++ 11 - STL - 函式物件(Function Object) (下)C++函式物件FunctionObject
- C++ STL 優先佇列 (priority_queue)C++佇列
- C++學習筆記 — STL標準模板庫C++筆記
- 跟我學C++中級篇——STL的學習C++
- C++圖書館管理系統 [STL實現]C++
- C++ 學習筆記(1):STL、Vector 與 SetC++筆記
- 7-20 簡單計算器 (20分)
- C++ STL:std::unorderd_map 物理結構詳解C++