zoukankan      html  css  js  c++  java
  • 【基础训练题解 3107 分苹果 】

     1 #include <iostream>
     2 #include <cmath>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     int t;
     8     cin >> t;
     9     while( t-- )
    10     {
    11         int n;
    12         cin >> n;
    13         int *a = new int[n];
    14         int sum = 0;
    15         
    16         // input data numbers that everyone own the apple 
    17         for(int i = 0; i < n; i++)
    18         {
    19             cin >> a[i];
    20         }
    21         //cout << "ism " << endl;
    22         int current = 0;
    23         
    24         for(int i = 0; i < n; i++)
    25         {
    26             while( a[i] < 0 )
    27             {
    28                 if(a[current] <= 0)
    29                 {
    30                     current++;
    31                 }
    32                 else
    33                 {
    34                     if((0-a[i]) <= a[current])
    35                     {
    36                         sum += fabs(current-i)*(0-a[i]);
    37                         a[current] -= (0-a[i]);
    38                         a[i] = 0;
    39                     }
    40                     else
    41                     {
    42                         sum += fabs(current-i)*(a[current]);
    43                         a[i] += a[current];
    44                         a[current] = 0;
    45                         current++;
    46                     }
    47                     
    48                 }
    49             }
    50         }
    51         
    52         cout << sum << endl;
    53         
    54         delete[] a;
    55     }
    56     
    57     return 0;
    58 }
    59 //end
    60 //ism
  • 相关阅读:
    MySQL
    MySQL -数据库备份
    MySQL
    MySQL
    MySQL
    MySQL
    MySQL
    MySQL
    MySQL
    53端口反弹shell
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2535299.html
Copyright © 2011-2022 走看看