- 题目链接:小明种苹果
- 满分代码
#include <iostream>
#include <algorithm>
using namespace std;
typedef struct TREE
{
int num; //编号
int sub; //疏果总数
int remain; //剩下的总数
}TREE;
TREE tree[1010];//存所有树
int sum = 0; //剩余的总果数
bool cmp(TREE a,TREE b)
{
if(a.sub!=b.sub)
return a.sub<b.sub; //先按疏果数升序排
return a.num<b.num; //再按编号升序
}
int main()
{
int N,M;
cin>>N>>M; //棵数,轮数
for(int i=1;i<=N;i++)
{
tree[i].num = i;
tree[i].sub = 0;
cin>>tree[i].remain;
sum += tree[i].remain;
int subTemp = 0;
for(int j=0;j<M;j++)
{
cin>>subTemp;
tree[i].sub += subTemp;
sum += subTemp;
}
tree[i].remain += tree[i].sub;
}
sort(tree+1,tree+N,cmp);
cout<<sum<<" "<<tree[1].num<<" "<<-tree[1].sub<<endl;
return 0;
}
- 说明:看清楚题就好