1 条题解

  • 1
    @ 2025-10-14 22:08:35

    亲测AC 包对

    AC code

    #include<queue>
    #include<math.h>
    #include<stdio.h>
    #include<iostream>
    #include<vector>
    #include<iomanip>
    #include<string.h>
    #include<algorithm>
    #include<cmath>
    #include<cstdio>
    #include<utility>
    #include<cstring>
    #include<stack>
    #include<fstream>
    #include<string>
    using namespace std;
    typedef long long ll;
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    int n;
    struct node
    {
    	long long sum , chinese , math , english ;
    	long long pm , bh ;
    }stud[10010]; 
    bool cmp( node x , node y )
    { 
    	if ( x.sum != y.sum )
    	{
    		return x.sum > y.sum;
    	}
    	else
    	{
    		if ( x.chinese + x.math != y.chinese + y.math )
    		{
    			return x.chinese + x.math > y.chinese + y.math;
    		}
    		else
    		{
    			if ( max( x.chinese , x.math ) != max( y.chinese , y.math ) )
    			{
    				return max( x.chinese , x.math ) > max( y.chinese , y.math );
    			}
    			else
    			{
    				return 0; 
    			}
    		}
    	}
    }
    bool cmp1( node x , node y )
    {
    	return x.bh < y.bh; 
    }
    int main()
    {
    	cin >> n;
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		cin >> stud[i].chinese >> stud[i].math >> stud[i].english;
    		stud[i].sum = stud[i].chinese+stud[i].math + stud[i].english;
    		stud[i].bh = i;
    	}
    	sort( stud + 1 , stud + 1 + n , cmp );
    	int cnt = 1;
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		if ( stud[i].sum == stud[ i - 1 ].sum
    		&& stud[i].chinese+stud[i].math == stud[ i - 1 ].chinese + stud[ i - 1 ].math
    		&& max( stud[i].chinese , stud[i].math ) == max( stud[ i - 1 ].chinese , stud[ i - 1 ].math ) )
    		{
    			stud[i].pm = cnt;
    		}
    		else
    		{
    			cnt = i;
    			stud[i].pm = cnt;
    		}
    	}
    	sort( stud + 1 , stud + 1 + n , cmp1 );
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		cout << stud[i].pm << "\n";
    	}
    	return 0;
    }
    
     100 Accepted
    Syncing testdata, please wait...
    #	状态分数	耗时	内存占用
    #1	 Accepted20	0ms	256 KiB
    #2	 Accepted20	0ms	256 KiB
    #3	 Accepted20	1ms	256 KiB
    #4	 Accepted20	6ms	796 KiB
    #5	 Accepted20	6ms	796 KiB
    代码
    #include<queue>
    #include<math.h>
    #include<stdio.h>
    #include<iostream>
    #include<vector>
    #include<iomanip>
    #include<string.h>
    #include<algorithm>
    #include<cmath>
    #include<cstdio>
    #include<utility>
    #include<cstring>
    #include<stack>
    #include<fstream>
    #include<string>
    using namespace std;
    typedef long long ll;
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    int n;
    struct node
    {
    	long long sum , chinese , math , english ;
    	long long pm , bh ;
    }stud[10010]; 
    bool cmp( node x , node y )
    { 
    	if ( x.sum != y.sum )
    	{
    		return x.sum > y.sum;
    	}
    	else
    	{
    		if ( x.chinese + x.math != y.chinese + y.math )
    		{
    			return x.chinese + x.math > y.chinese + y.math;
    		}
    		else
    		{
    			if ( max( x.chinese , x.math ) != max( y.chinese , y.math ) )
    			{
    				return max( x.chinese , x.math ) > max( y.chinese , y.math );
    			}
    			else
    			{
    				return 0; 
    			}
    		}
    	}
    }
    bool cmp1( node x , node y )
    {
    	return x.bh < y.bh; 
    }
    int main()
    {
    	cin >> n;
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		cin >> stud[i].chinese >> stud[i].math >> stud[i].english;
    		stud[i].sum = stud[i].chinese+stud[i].math + stud[i].english;
    		stud[i].bh = i;
    	}
    	sort( stud + 1 , stud + 1 + n , cmp );
    	int cnt = 1;
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		if ( stud[i].sum == stud[ i - 1 ].sum
    		&& stud[i].chinese+stud[i].math == stud[ i - 1 ].chinese + stud[ i - 1 ].math
    		&& max( stud[i].chinese , stud[i].math ) == max( stud[ i - 1 ].chinese , stud[ i - 1 ].math ) )
    		{
    			stud[i].pm = cnt;
    		}
    		else
    		{
    			cnt = i;
    			stud[i].pm = cnt;
    		}
    	}
    	sort( stud + 1 , stud + 1 + n , cmp1 );
    	for ( int i = 1 ; i <= n ; i++ )
    	{
    		cout << stud[i].pm << "\n";
    	}
    	return 0;
    }
    信息
    递交者 吴灏霖小号 LV 9题目3310   成绩排序语言C++ 17代码长度1.7 KiB递交时间2025-10-14 22:06:05
    分数100总耗时14ms峰值时间6ms峰值内存796 KiB
    

    请点赞再走,谢谢!!!

    • 1

    信息

    ID
    3310
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    89
    已通过
    16
    上传者