• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
CodeForces 686A Free Ice Cream (水题模拟)

题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于,

那么孩子就会离家。问你最后剩下多少冰激凌,和出走的孩子数量。

析:多水的一个题,就是一个模拟,如果是+,就加上,如果是‘-’,就判断一下,如果不够,就记录下来。

代码如下:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;
typedef long long LL;
char s[5];

int main(){
    int n, x;
    LL sum = 0, t;
    int ans = 0;
    scanf("%d %d", &n, &x);
    sum += x;
    for(int i = 0; i < n; ++i){
        scanf("%s", s);
        scanf("%lld", &t);
        if('+' == s[0])  sum += t;
        else {
            if(sum >= t)  sum -= t;
            else  ++ans;
        }
    }
    printf("%lld %d\n", sum, ans);
    return 0;
}

 

posted on 2016-07-05 23:53  dwtfukgv  阅读(226)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3