题目:https://www.luogu.org/problemnew/show/P1583
思路:sort sort sort
1 //#include<bits/stdc++.h> 2 #include<set> 3 #include<iostream> 4 #include<stdio.h> 5 #include<stdlib.h> 6 #include<cstring> 7 #include<stack> 8 #include<algorithm> 9 10 using namespace std; 11 12 int n, k; 13 struct node{ 14 int id, w; 15 }peo[20005]; 16 int e[11]; 17 18 bool cmp(node a, node b) 19 { 20 if(a.w == b.w)return a.id < b.id; 21 return a.w > b.w; 22 } 23 24 int main() 25 { 26 scanf("%d%d", &n, &k); 27 for(int i = 1; i <= 10; i++){ 28 scanf("%d", &e[i]); 29 } 30 for(int i = 1; i <= n; i++){ 31 scanf("%d", &peo[i].w); 32 peo[i].id = i; 33 } 34 sort(peo + 1, peo + 1 + n, cmp); 35 /*for(int i = 1; i <= n; i++){ 36 printf("%d ", peo[i].id); 37 }*/ 38 for(int i = 1; i <= n; i++){ 39 peo[i].w += e[(i - 1) % 10 + 1]; 40 } 41 sort(peo + 1, peo + 1 + n, cmp); 42 for(int i = 1; i <= k; i++){ 43 printf("%d ", peo[i].id); 44 } 45 printf(" "); 46 47 return 0; 48 }
题目:https://www.luogu.org/problemnew/show/P1051
思路:模拟拿奖学金的情况,找最大值。
1 //#include<bits/stdc++.h> 2 #include<set> 3 #include<iostream> 4 #include<stdio.h> 5 #include<stdlib.h> 6 #include<cstring> 7 #include<stack> 8 #include<algorithm> 9 10 using namespace std; 11 12 int n; 13 struct node{ 14 string name; 15 int sco, csco; 16 char ganbu, west; 17 int paper; 18 int money = 0; 19 }stu[105]; 20 21 22 int main() 23 { 24 scanf("%d", &n); 25 int mmm = 0, id = 0, sum = 0; 26 for(int i = 0; i < n; i++){ 27 cin>>stu[i].name>>stu[i].sco>>stu[i].csco>>stu[i].ganbu>>stu[i].west>>stu[i].paper; 28 if(stu[i].sco > 80 && stu[i].paper >= 1){ 29 stu[i].money += 8000; 30 } 31 if(stu[i].sco > 85 && stu[i].csco > 80){ 32 stu[i].money += 4000; 33 } 34 if(stu[i].sco > 90){ 35 stu[i].money += 2000; 36 } 37 if(stu[i].sco > 85 && stu[i].west == 'Y'){ 38 stu[i].money += 1000; 39 } 40 if(stu[i].csco > 80 && stu[i].ganbu == 'Y'){ 41 stu[i].money += 850; 42 } 43 sum += stu[i].money; 44 if(stu[i].money > mmm){ 45 id = i; 46 mmm = stu[i].money; 47 } 48 } 49 cout<<stu[id].name<<endl; 50 cout<<mmm<<endl; 51 cout<<sum<<endl; 52 return 0; 53 }
题目:https://www.luogu.org/problemnew/show/P1093
思路:sort
1 //#include<bits/stdc++.h> 2 #include<set> 3 #include<iostream> 4 #include<stdio.h> 5 #include<stdlib.h> 6 #include<cstring> 7 #include<stack> 8 #include<algorithm> 9 10 using namespace std; 11 12 struct node{ 13 int id; 14 int chinese; 15 int math; 16 int eng; 17 }stu[305]; 18 int n; 19 20 bool cmp(node a, node b) 21 { 22 if(a.chinese + a.math + a.eng == b.chinese + b.math + b.eng){ 23 if(a.chinese == b.chinese){ 24 return a.id < b.id; 25 } 26 else return a.chinese > b.chinese; 27 } 28 else return a.chinese + a.math + a.eng > b.chinese + b.math + b.eng; 29 } 30 31 int main() 32 { 33 scanf("%d", &n); 34 for(int i = 0; i <n; i++){ 35 scanf("%d%d%d", &stu[i].chinese, &stu[i].math, &stu[i].eng); 36 stu[i].id = i + 1; 37 } 38 sort(stu, stu + n, cmp); 39 for(int i = 0; i < 5; i++){ 40 printf("%d %d ", stu[i].id, stu[i].chinese + stu[i].math + stu[i].eng); 41 } 42 return 0; 43 }