原题:
Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA found that he was trapped by all kinds of suggestions from everyone on the board. It is indeed a mission-impossible to have everybody perfectly satisfied. So he took a poll to collect people's opinions. Here are what he obtained: N people voted for M design elements (such as the ACM-ICPC logo, big names in computer science, well-known graphs, etc.). Everyone assigned each element a number of satisfaction. However, XKA can only put K (<=M) elements into his design. He needs you to pick for him the K elements such that the total number of satisfaction is maximized.
题意:
假设用n种T恤,然后m个人分别对这n种T恤打分,要计算出哪几种T恤的得分和最高。
题解:
创建结构体包括:T恤序号,T恤得分总和
输入数据依次得到T恤的得分总和,排序输出就得了
(这题解真的太糊弄了,主要也是前边的这些题就是模拟一下排序一下就好了)
主要学习一下结构体的sort的用法
就酱
代码:AC
#include<iostream>
using namespace std;
struct nom
{
int No=0;
double sat=0;
};
int n, m, k;
double **bank;
nom *ans;
int main(void)
{
while (cin >> n >> m >> k)
{
bank = new double*[n];
ans = new nom[m];
for (int i = 0; i < n; i++)
{
bank[i] = new double[m];
for (int j = 0; j < m; j++)
{
cin >> bank[i][j];
ans[j].No = j+1;
ans[j].sat += bank[i][j];
}
}
for (int i = 1; i < m; i++)
for (int j = 0; j < m - i;j++)
{
if (ans[j].sat < ans[j + 1].sat)
{
nom s = ans[j]; ans[j] = ans[j + 1]; ans[j + 1] = s;
}
}
for (int i = 1; i < k; i++)
for (int j = 0; j < k - i; j++)
{
if (ans[j].No < ans[j + 1].No)
{
nom s = ans[j]; ans[j] = ans[j + 1]; ans[j + 1] = s;
}
}
for (int i = 0; i < k; i++)
{
cout << ans[i].No ;
if (i < k - 1)
cout << ' ';
else
cout << endl;
}
}
return 0;
}