5 条题解

  • 3
    @ 2024-3-1 20:49:17

    暴力枚举

    #include <iostream>
    using namespace std;
    int main()
    {
        int n, a[20005], sum = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
        for (int i = 1; i < n; i++)
        {
            for (int j = i + 1; j <= n; j++)
            {
                if (a[j] < a[i])
                {
                    sum++;
                }
            }
        }
        cout << sum;
        return 0;
    }
    
    • 1
      @ 2023-10-4 10:11:42

      暴力枚举即可(数据范围又不大)

      #include<bits/stdc++.h>
      using namespace std;
      int n,a[20005],ans;
      int main(){
          scanf("%d",&n);
          for(int i=1;i<=n;i++) scanf("%d",&a[i]);
          for(int i=1;i<=n;i++)
              for(int j=i+1;j<=n;j++)
                  if(a[i]>a[j])
                      ans++;
          printf("%d\n",ans);
          return 0;
      }
      
      • 0
        @ 2023-7-14 19:06:33

        其实它是类似枚举和选择排序

        #include <iostream>
        using namespace std;
        int main(){
            int n,a[20001],num=0;
            cin>>n;
            for(int i=0;i<n;i++)cin>>a[i];
            for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)if(a[j]<a[i])num++;
            cout<<num<<endl;
            return 0;
        }
        
        • 0
          @ 2023-1-29 14:53:48
          #include<bits/stdc++.h>
          using namespace std;
          int a[210];
          int main()
          {
          	int n, c = 0, j;
          	cin >> n;
          	for(int i = 1; i <= n; i++){
          		cin >> a[i];
          	}
          	for(int i = n; i >= 1; i--){
          		j = i;
          		while(j <= n){
          			if(a[i] > a[j]){
          				c++;
          			}
          			j++;
          		}
          	}
          	cout << c << endl;
          	return 0;
          }
          
          
          • 0
            @ 2023-1-20 18:54:28

            额————

            #include <iostream>
            using namespace std;
            int n,a[20001],sum=0;
            int main()
            {
                cin >> n;
                for(int i=1;i<=n;i++)
                {
                    cin >> a[i];
                }
                for(int i=2;i<=n;i++)
                {
                    if(a[i]<a[i-1])
                    {
                        sum+=a[i];
                    }
                }
                cout << sum-1;
            }
            
            • 1

            信息

            ID
            215
            时间
            1000ms
            内存
            16MiB
            难度
            1
            标签
            递交数
            69
            已通过
            48
            上传者