4 条题解

  • 0
    @ 2024-3-17 19:50:50
    #include<bits/stdc++.h>
    using namespace std;
    const int N = 1e5 + 10;
    int n,k;
    struct stu
    {
    	int id;
    	int yw;
    	int sx;
    	int yy;
    	int total;
    }a[N];
    bool cmp(stu a1,stu a2)
    {
    	if(a1.total == a2.total)
    	{
    	    if(a1.yw == a2.yw)
    	    {
    	        if(a1.sx == a2.sx)
    	        {
    	            if(a1.yy == a2.yy)
    	            {
    	                a1.id < a2.id;
    	            }
    	            return a1.yy > a2.yy;
    	        }
    	        return a1.sx > a2.sx;
    	    }
    	    return a1.yw > a2.yw;
    	}
    	return a1.total > a2.total;
    }
    int main(){
        cin >> n >> k;
        for(int i = 1;i <= n;i++)
        {
            cin >> a[i].id >> a[i].yw >> a[i].sx >> a[i].yy;
            a[i].total = a[i].yw + a[i].sx + a[i].yy;
        }
        sort(a + 1,a + n + 1,cmp);
        cout << a[k].id << " " << a[k].yw << " " << a[k].sx << " " << a[k].yy << " " << a[k].total;
        return 0;
    }
    
    • 0
      #include<stdio.h>
      #include<string.h>
      #include<queue>
      #include<math.h>
      #include<vector>
      #include<algorithm>
      #include<iomanip>
      #include<stack>
      #define LL long long
      using namespace std;
      const int INF=0x3f3f3f3f;
      const int N=2e5+10;
      struct stt
      {
      	int id;
      	int yw;
      	int sx;
      	int yy;
      	int zf;
      }a[N];
      
      int n,k;
      bool cmp(stt a1,stt a2){
      	if(a1.zf==a2.zf){
      		if(a1.yw==a2.yw){
      			if(a1.sx==a2.sx){
      				if(a1.yy==a2.yy)
      					return a1.id<a2.id;
      				return a1.yy>a2.yy;
      			}
      			return a1.sx>a2.sx;
      		}
      		return a1.yw>a2.yw;
      	}
      	return a1.zf>a2.zf;
      }
      int main(){
      	cin>>n>>k;
      	for(int i=1;i<=n;i++){
      		cin>>a[i].id>>a[i].yw>>a[i].sx>>a[i].yy;
      		a[i].zf=a[i].yw+a[i].sx+a[i].yy;
      	}
      	sort(a+1,a+n+1,cmp);
      	cout<<a[k].id<<" "<<a[k].yw<<" "<<a[k].sx<<" "<<a[k].yy<<" "<<a[k].zf;
      	return 0;
      } 
      
      • 0
        @ 2024-3-17 18:25:59
        #include<bits/stdc++.h>
        using namespace std;
        const int N=1e4+10;
        const int INF=0x3f3f3f3f;
        
        	struct stu
        	{
        		int id;
        		int yw;
        		int sx;
        		int yy;
        		int totle;
        	}a[N];
        	int n,k;
        	bool cmp(stu a1,stu a2){
        		if(a1.totle==a2.totle){
        			if(a1.yw==a2.yw){
        				if(a1.sx==a2.sx){
        					if(a1.yy==a2.yy)
        						return a1.id<a2.id;				
        						return a1.yy>a2.yy;
        				}
        				return a1.sx>a2.sx;
        			}
        			return a1.yw>a2.yw;
        		}
        		return a1.totle>a2.totle;
        	}
        int main(){
        	cin>>n>>k;
        	for(int i=1;i<=n;i++){
        		cin>>a[i].id>>a[i].yw>>a[i].sx>>a[i].yy;
        		a[i].totle=a[i].yw+a[i].sx+a[i].yy;
        	}
        	sort(a+1,a+n+1,cmp);
        	cout<<a[k].id<<" "<<a[k].yw<<" "<<a[k].sx<<" "<<a[k].yy<<" "<<a[k].totle; 
        	return 0;
        }
        
        • 0
          @ 2023-6-6 18:17:02
          #include <iostream>
          #include <algorithm>
          using namespace std;
          struct Student
          {
              int no;
              int chinese;
              int math;
              int english;
              int total;
          };
          bool cmp(Student a, Student b)
          {
              if (a.total != b.total)
              {
                  return a.total > b.total;
              }
              else if (a.chinese != b.chinese)
              {
                  return a.chinese > b.chinese;
              }
              else if (a.math != b.math)
              {
                  return a.math > b.math;
              }
              else if (a.english != b.english)
              {
                  return a.english > b.english;
              }
              else
              {
                  return a.no < b.no;
              }
          }
          int main()
          {
              int n, k;
              cin >> n >> k;
              Student students[n];
              for (int i = 0; i < n; i++)
              {
                  cin >> students[i].no >> students[i].chinese >> students[i].math >> students[i].english;
                  students[i].total = students[i].chinese + students[i].math + students[i].english;
              }
              sort(students, students + n, cmp);
              cout << students[k - 1].no << " " << students[k - 1].chinese << " " << students[k - 1].math << " " << students[k - 1].english << " " << students[k - 1].total;
              return 0;
          }
          
          • 1

          信息

          ID
          1363
          时间
          1000ms
          内存
          256MiB
          难度
          6
          标签
          递交数
          327
          已通过
          105
          上传者