My Friend of Misery Gym - 101086A——思维题

19 篇文章 1 订阅

原题链接:https://codeforces.com/gym/101086/problem/A

With the SCPC2015 getting closer, Noura Boubou, SCPC Head of Media, was very busy to the extent of not having time to recharge her phone's credit balance. However, her best friend, Nicole, was kind enough to transfer her own credit for the sake of keeping Noura online 24/7.

The phone credit transfer system in Syria works in the following way: Each successful transfer operation withdraws 25 extra credit units from the sender's balance, but it doesn't cost anything when a transfer operation is unsuccessful due to non sufficient credit balance.

Given the log of credit transfer requests and the response from the system to each request, in the form: Amount of transfer, and result of operation (either successful or unsuccessful), can you find out the number of possible initial credit balance values that Nicole could have had which satisfy the given log file?

Note that the initial credit balance is always a non negative integer.

Input

The first line of input contains an integer T (1 ≤ T ≤ 256), the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 105), the number of operations in the log of credit transfer requests.

Each of the following N lines contains an integer mi (1 ≤ mi ≤ 106), the amount of credit to transfer, followed by .

  • { + } denotes a successful operation.
  • { - } denotes an unsuccessful operation.

Each log contains at least one unsuccessful operation.

Output

For each test case, print a single line that contains the number of possible initial credit balance values that Nicole could have had.

题意:

要求出的是sender可以拥有的流量费的所有种可能。

注意:

第一次出现  -   的时候,他当时所可以拥有的流量费的最大值一定是他拥有流量费的上界,所以第一次出现  -  的时候特判一下。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
const ll N = 1e5+10;

int main()
{
     int T;
     cin>>T;
     while(T--)
     {
          int n;
          cin>>n;
          int sum = 0;
          int pl = 0;
          int i=1;
          for(i=1; i<=n; i++)
          {
               int x;
               char c;
               cin>>x>>c;
               if(c=='+')
               {
                    sum = sum + x + 25;
               }
               else
               {
                    pl = sum + x + 24;
                    i++;
                    break;
               }
          }
          for(;i<=n; i++)
          {
               int x;
               char c;
               cin>>x>>c;
               if(c=='+')
               {
                    sum = sum + x + 25;
               }
               else
               {
                    if(sum+x+25<=pl)
                         pl = sum + x + 24;
               }
          }

          cout<<pl-sum+1<<endl;
     }
     return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值