首页 > 其他分享 >洛谷题单指南-排序-P1093 [NOIP2007 普及组] 奖学金

洛谷题单指南-排序-P1093 [NOIP2007 普及组] 奖学金

时间:2024-01-29 10:11:48浏览次数:22  
标签:NOIP2007 int 洛谷题 s1 yuwen P1093 s2 total

原题链接:https://www.luogu.com.cn/problem/P1093

题意解读:本题考察排序,根据题意,先按总分从大到小排,再按语文从大到小排,以上都相同则按学号从小到大排。

100分代码:

#include <bits/stdc++.h>
using namespace std;

const int N = 305;

struct student
{
    int id;
    int yuwen;
    int shuxue;
    int yingyu;
    int total;
} s[N];

bool cmp(student s1, student s2)
{
    if(s1.total != s2.total) return s1.total > s2.total;
    if(s1.yuwen != s2.yuwen) return s1.yuwen > s2.yuwen;
    return s1.id < s2.id;
}

int n;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        s[i].id = i;
        cin >> s[i].yuwen >> s[i].shuxue >> s[i].yingyu;
        s[i].total = s[i].yuwen + s[i].shuxue + s[i].yingyu;
    }

    sort(s + 1, s + n + 1, cmp);

    for(int i = 1; i <= 5; i++) cout << s[i].id << " " << s[i].total << endl;

    return 0;
}

 

标签:NOIP2007,int,洛谷题,s1,yuwen,P1093,s2,total
From: https://www.cnblogs.com/jcwy/p/17993905

相关文章

  • 洛谷题单指南-排序-P1059 [NOIP2006 普及组] 明明的随机数
    原题链接:https://www.luogu.com.cn/problem/P1059题意解读:此题主要做两件事:排序+去重,用计数排序即可解决,直接给出代码。100分代码:#include<bits/stdc++.h>usingnamespacestd;constintN=1005;inta[N];intn;intmain(){cin>>n;intx;intcnt......
  • 洛谷题解-[ARC001B] リモコン
    https://www.luogu.com.cn/problem/AT_arc001_2题目描述 输入格式无输出格式无题意翻译题目描述:高桥君要调整空调的设定温度。现在的设定温度是A度,而他想调到B度。空调遥控器按一次可以:上调或下调1度上调或下调5度上调或下调10度高桥君想求出从A调到B度的最小......
  • 洛谷题解-P1938 [USACO09NOV] Job Hunt S
    https://www.luogu.com.cn/problem/P1938题目描述Bessieisrunningoutofmoneyandissearchingforjobs.FarmerJohnknowsthisandwantsthecowstotravelaroundsohehasimposedarulethathiscowscanonlymakeD(1<=D<=1,000)dollarsinac......
  • 洛谷题解-P2888 [USACO07NOV] Cow Hurdles S (Floyd)
    https://www.luogu.com.cn/problem/P2888题目描述FarmerJohnwantsthecowstoprepareforthecountyjumpingcompetition,soBessieandthegangarepracticingjumpingoverhurdles.Theyaregettingtired,though,sotheywanttobeabletouseaslittleene......
  • 洛谷题解-P3003 [USACO10DEC] Apple Delivery S (dijkstra)
    题目描述Bessiehastwocrispredapplestodelivertotwoofherfriendsintheherd.Ofcourse,shetravelstheC(1<=C<=200,000)cowpathswhicharearrangedastheusualgraphwhichconnectsP(1<=P<=100,000)pasturesconvenientlynumb......
  • 洛谷题单指南-排序-P1923 【深基9.例4】求第 k 小的数
    原题链接:https://www.luogu.com.cn/problem/P1923题意解读:要最快的求第k小的数,O(n)的做法是利用快排的思想对数据进行划分第一步、取分界点x,通常设x=a[(l+r)/2]第二步、将小于x的挪到x左边,将大于x的挪到x右边第三步、比较,如果x左边的个数大于k,则继续递归处理左边,否则递......
  • 洛谷题解-P1821 [USACO07FEB] Cow Party S
    https://www.luogu.com.cn/problem/P1821题目描述寒假到了,nnn头牛都要去参加一场在编号为xxx的牛的农场举行的派对,农场之间有mmm条有向路,每条路都有一定的长度。每头牛参加完派对后都必须回家,无论是去参加派对还是回家,每头牛都会选择最短路径,求这nnn头牛的最短路径(一个......
  • 洛谷题解-P1673 [USACO05FEB] Part Acquisition S
    https://www.luogu.com.cn/problem/P1673题目描述奶牛们接到了寻找一种新型挤奶机的任务,为此它们准备依次经过N(1≤N≤5×104)N(1\leN\le5\times10^4)N(1≤N≤5×104)颗行星,在行星上进行交易。为了方便,奶牛们已经给可能出现的K(1≤K≤103)K(1\leK\le10^3)K(1≤K≤103)......
  • 洛谷题单指南-排序-P1177 【模板】排序
    原题链接:https://www.luogu.com.cn/problem/P1177题意解读:数据量为100000,必须用小于等于N*logN复杂度的排序算法,可以直接用sort,更重要需要掌握快速排序的过程。知识点:快速排序设定数组q[n],l,r第一步:确定分界点x可以取q[l]、q[(l+r)/2]、q[r]三种第二步:调整区间把<=x的数调......
  • 洛谷题解-P2712 摄像头
    https://www.luogu.com.cn/problem/P2712可以看出是拓扑排序,因为是有前后关系的,但是坑点在于点并不连续,值得记录一下(刚开始70分,后来才AC)注意坑点:拓扑排序,遍历的点不连续 #include<bits/stdc++.h>usingnamespacestd;constintN=1e5+5;intn,x,m,y,d[N],cnt=0,v......