6 条题解

  • 0
    @ 2024-11-19 17:14:06
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    const int INF=0x3f3f3f;
    int n,k;
    struct stu{
    	int id;
    	int chinese;
    	int math;
    	int english;
    	int total;
    };
    stu a[60];
    bool cmp(stu a1,stu a2){
    	if(a1.total==a2.total){
    		if(a1.chinese==a2.chinese){
    			if(a1.math==a2.math){
    				if(a1.english==a2.english){
    					return a1.id<a2.id;		
    	}
    		return a1.english>a2.english;
    	}
    		return a1.math>a2.math;
    	}	
    		return a1.chinese>a2.chinese;
    	}
    	return a1.total>a2.total;
    }
    int main(){
    	cin>>n>>k;
    	for(int i=1;i<=n;i++){
    		cin>>a[i].id>>a[i].chinese>>a[i].math>>a[i].english;
    		a[i].total=a[i].chinese+a[i].math+a[i].english;
    	}
    	sort(a+1,a+n+1,cmp);
    	cout<<a[k].id<<" "<<a[k].chinese<<" "<<a[k].math<<" "<<a[k].english<<" "<<a[k].total<<" ";
    	
    
    	return 0;
    }
    @小鸟
    
    • 0
      @ 2024-11-19 17:01:38

      最简代码

      #include<bits/stdc++.h>
      using namespace std;
      
      const int N=1e4+10;
      struct cc{
      	int n;
      	int a;
      	int b;
      	int c;
      	int t;
      };
      
      bool _666(cc n1,cc n2){
      	if(n1.t==n2.t){
      		if(n1.a==n2.a){
      			if(n1.b==n2.b){
      				if(n1.c==n2.c){
      					return n1.n<n2.n;
      				}
      				return n1.c>n2.c;
      			}
      			return n1.b>n2.b;
      		}
      		return n1.a>n2.a;
      	}
      	return n1.t>n2.t;
      }
      cc cnm[N];
      int x,y;
      
      int main(){
      	cin>>x>>y;
      	for(int i=1;i<=x;i++){
      		cin>>cnm[i].n>>cnm[i].a>>cnm[i].b>>cnm[i].c;
      		cnm[i].t=cnm[i].a+cnm[i].b+cnm[i].c;
      	}
      	sort(cnm+1,cnm+x+1,_666);
      	cout<<cnm[y].n<<" "<<cnm[y].a<<" "<<cnm[y].b<<" "<<cnm[y].c<<" "<<cnm[y].t;
      	return 0;
      }
      
      • 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
              标签
              递交数
              355
              已通过
              121
              上传者