1 solutions

  • 2
    @ 2024-12-2 21:07:27
    a?b:c;
    

    其中,a、b 和 c 是表达式。请注意冒号的使用和位置。? : 表达式的值取决于 a 的计算结果。如果 a 为真,则计算 b 的值,且 b 的计算结果则为整个 ? : 表达式的值。如果 a 为假,则计算 c 的值,且 c 的计算结果则为整个 ? : 表达式的值。

    ? 被称为三元运算符,因为它需要三个操作数,可以用来代 if-else 语句

    so 难点解释完了,那么Please let me show

    代码:

    #include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    const int N=10010;
    int w[N],s[N];
    int maxx;
    int n,m;
    int main(){
    	
    	cin.sync_with_stdio(false);
    	ios::sync_with_stdio(0);
    	cin.tie(0);cout.tie(0);
    	cin>>n>>m;
    	for(int i=1;i<=n;i++)cin>>w[i];
    	for(int i=1;i<=n;i++){
    		maxx=1;
    		for(int j=2;j<=m;j++){
    			if(s[maxx]>s[j]){
    				maxx=j;
    			}
    		}
    		s[maxx]+=w[i];
    	}
    	maxx=1;
    	for(int i=1;i<=m;i++){
    		maxx=s[i]>maxx?s[i]:maxx;
    	}
    	cout<<maxx;
    	
    	return 0;
    }
    
    • 1

    Information

    ID
    413
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    (None)
    # Submissions
    23
    Accepted
    11
    Uploaded By