ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CF686A Free Ice Cream(洛谷+模拟)

2021-10-22 21:31:06  阅读:177  来源: 互联网

标签:CF686A 洛谷 packs 冰淇淋 Ice cin long 20 tmp2


题目描述

凯和格尔达开了个冰淇凌店。他们最开始有x个冰淇淋。冰淇淋是免费的。人们可以给他们提供d个冰淇淋,也可以从他们这里要d个冰淇淋。若他们的冰淇淋不够给要冰淇淋的人,要冰淇淋的人会失落,他们的冰淇淋不会减少。他们想知道收摊以后,他们还剩多少冰淇淋和有多少失落的人。

输入输出格式

输入格式

输入n,x(1<=n<=1000,0<=x<=10^9),表示有n个人,最开始有x个冰淇淋 接下来每行输入‘+’或‘-’和d,“+ d”表示有人给了d个冰淇淋,“- d”表示有人想要d个冰淇淋

输出格式

输出两个数,剩的冰淇淋数和失落的人数

输入输出样例

输入 #1
5 7
+ 5
- 10
- 20
+ 40
- 20
输出 #1
22 1
输入 #2
5 17
- 16
- 2
- 98
+ 100
- 98
输出 #2
3 2

说明/提示

Consider the first sample.

  1. Initially Kay and Gerda have 7 packs of ice cream.
  2. Carrier brings 5 more, so now they have 12 packs.
  3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
  4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
  5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
  6. Kid asks for 20 packs and receives them. There are 22 packs remaining

CODE

#include <iostream>
using namespace std;

typedef long long ll;
ll n, x, tmp2, cnt;
char tmp1;

int main(){
	cin >> x >> n;
	while(x--){
		cin >> tmp1 >> tmp2;
		if(tmp1 == '+')
			n += tmp2;
		else if(tmp2 > n)
			cnt++;
		else if(tmp2 < n)
			n -= tmp2;
	}
	cout << n << " " << cnt << endl;
	return 0;
}

当然这样做是错的

AC·CODE

#include <iostream>
using namespace std;

long long n, x, ans;
int a[1010]; 
char c[1010];

int main(){
	ios::sync_with_stdio(false);  
	cin.tie(0);
	cin >> n >> x;
	for(int i=1; i<=n; i++){
		cin >> c[i] >> a[i];
		if(c[i] == '-')a[i] *= -1;
		if(x + a[i] >= 0)x += a[i];
		else ans++;
	}
	cout << x << " " << ans << endl;
	return 0; 
}

标签:CF686A,洛谷,packs,冰淇淋,Ice,cin,long,20,tmp2
来源: https://www.cnblogs.com/zjy15000284340/p/15440709.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有