题目:https://www.luogu.org/problemnew/show/P1583
思路:sort sort sort
//#include<bits/stdc++.h>
#include<set>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<stack>
#include<algorithm> using namespace std; int n, k;
struct node{
int id, w;
}peo[];
int e[]; bool cmp(node a, node b)
{
if(a.w == b.w)return a.id < b.id;
return a.w > b.w;
} int main()
{
scanf("%d%d", &n, &k);
for(int i = ; i <= ; i++){
scanf("%d", &e[i]);
}
for(int i = ; i <= n; i++){
scanf("%d", &peo[i].w);
peo[i].id = i;
}
sort(peo + , peo + + n, cmp);
/*for(int i = 1; i <= n; i++){
printf("%d\n", peo[i].id);
}*/
for(int i = ; i <= n; i++){
peo[i].w += e[(i - ) % + ];
}
sort(peo + , peo + + n, cmp);
for(int i = ; i <= k; i++){
printf("%d ", peo[i].id);
}
printf("\n"); return ;
}
题目:https://www.luogu.org/problemnew/show/P1051
思路:模拟拿奖学金的情况,找最大值。
//#include<bits/stdc++.h>
#include<set>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<stack>
#include<algorithm> using namespace std; int n;
struct node{
string name;
int sco, csco;
char ganbu, west;
int paper;
int money = ;
}stu[]; int main()
{
scanf("%d", &n);
int mmm = , id = , sum = ;
for(int i = ; i < n; i++){
cin>>stu[i].name>>stu[i].sco>>stu[i].csco>>stu[i].ganbu>>stu[i].west>>stu[i].paper;
if(stu[i].sco > && stu[i].paper >= ){
stu[i].money += ;
}
if(stu[i].sco > && stu[i].csco > ){
stu[i].money += ;
}
if(stu[i].sco > ){
stu[i].money += ;
}
if(stu[i].sco > && stu[i].west == 'Y'){
stu[i].money += ;
}
if(stu[i].csco > && stu[i].ganbu == 'Y'){
stu[i].money += ;
}
sum += stu[i].money;
if(stu[i].money > mmm){
id = i;
mmm = stu[i].money;
}
}
cout<<stu[id].name<<endl;
cout<<mmm<<endl;
cout<<sum<<endl;
return ;
}
题目:https://www.luogu.org/problemnew/show/P1093
思路:sort
//#include<bits/stdc++.h>
#include<set>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<stack>
#include<algorithm> using namespace std; struct node{
int id;
int chinese;
int math;
int eng;
}stu[];
int n; bool cmp(node a, node b)
{
if(a.chinese + a.math + a.eng == b.chinese + b.math + b.eng){
if(a.chinese == b.chinese){
return a.id < b.id;
}
else return a.chinese > b.chinese;
}
else return a.chinese + a.math + a.eng > b.chinese + b.math + b.eng;
} int main()
{
scanf("%d", &n);
for(int i = ; i <n; i++){
scanf("%d%d%d", &stu[i].chinese, &stu[i].math, &stu[i].eng);
stu[i].id = i + ;
}
sort(stu, stu + n, cmp);
for(int i = ; i < ; i++){
printf("%d %d\n", stu[i].id, stu[i].chinese + stu[i].math + stu[i].eng);
}
return ;
}