Codeforces 1159A A pile of stones
题目链接:http://codeforces.com/problemset/problem/1159/A


题意:初始石头堆石子数未知,求进行 n 次加减操作后,石头堆石子数最小的可能是多少。
思路:正常模拟就好了,题意理解了老半天orz! 开始数量未知,所以模拟的答案是负数的话,最小可能就是0。
AC代码:
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int n;
char a;
cin >> n ;
int ans = ;
for(int i = ;i < n;i++)
{
cin >> a;
if(a == '+') ans++;
else if(ans > )ans--;
}
cout << max(ans,) << endl;
return ;
}
Codeforces 1159A A pile of stones的更多相关文章
- Codeforces 768 E. Game of Stones 博弈DP
E. Game of Stones Sam has been teaching Jon the Game of Stones to sharpen his mind and help him de ...
- 【codeforces 768E】Game of Stones
[题目链接]:http://codeforces.com/contest/768/problem/E [题意] NIM游戏的变种; 要求每一堆石头一次拿了x个之后,下一次就不能一次拿x个了; 问你结果 ...
- [Codeforces Gym] 100162B Circle of Stones
题意: 桌子上有 n 个石头围成一个环.每个石头都有一种颜色.每种颜色可以由小写英文字母表示.如果每一对相邻的石头都是不同颜色的,则称这 n 个石头构成的环是美丽的.现在,你可以从这 n 个石头中拿走 ...
- [LeetCode] Minimum Cost to Merge Stones 混合石子的最小花费
There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. A move consists ...
- [Swift]LeetCode1000. 合并石头的最低成本 | Minimum Cost to Merge Stones
There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. A move consists ...
- 1000. Minimum Cost to Merge Stones
There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. A move consists ...
- LeetCode 1000. Minimum Cost to Merge Stones
原题链接在这里:https://leetcode.com/problems/minimum-cost-to-merge-stones/ 题目: There are N piles of stones ...
- LightOJ 1247 Matrix Game (尼姆博弈)
A - Matrix Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submi ...
- [Swift]LeetCode877. 石子游戏 | Stone Game
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, ...
随机推荐
- BZOJ 2005: [Noi2010]能量采集(容斥+数论)
传送门 解题思路 首先题目要求的其实就是\(\sum\limits_{i=1}^n \sum\limits_{j=1}^m [(gcd(i,j)-1)*2+1)]\),然后变形可得\(-n*m+2\s ...
- 学习android文档
follow lesson, 一. 创建一helloworld,运行.fragment_main.xml里默认是relativeLayout和Textview 二. 创建第一个图形界面,主要是说fra ...
- Wannafly Winter Camp Day8(Div1,onsite) E题 Souls-like Game 线段树 矩阵乘法
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog @ Problem:传送门 Portal 原题目描述在最下面. 简单的 ...
- Linux c基本知识整理
1.指针和引用的区别 1.指针是一个变量,变量存储一个地址指向内存中一个存储单元,需要单独分配内存空间.引用相当于变量的别名,不需要单独分配空间 2.引用必须初始化,指针可以先不进行初始化 3.指针可 ...
- MDK中问题:warning : type qualifier is meaningless on cast type return 的解决
在MDK编译代码时,有时会出现这样的警告, warning : type qualifier is meaningless on cast type return 在MDK中,作如下设置: 即添加 : ...
- socket API CSocket CAsyncSocket 用法及区别
要进行网络编程就要和Socket打交道,Socket有同步阻塞方式和异步非阻塞方式两种使用,事实上同步和异步在我们编程的生涯中可能遇到了很多,而Socket也没什么特别.虽然同步好用,不费劲,但不能满 ...
- java线程池和五种常用线程池的策略使用与解析
java线程池和五种常用线程池策略使用与解析 一.线程池 关于为什么要使用线程池久不赘述了,首先看一下java中作为线程池Executor底层实现类的ThredPoolExecutor的构造函数 pu ...
- python面试题之你如何管理不同版本的代码?
答案: 版本管理!被问到这个问题的时候,你应该要表现得很兴奋,甚至告诉他们你是如何使用Git(或是其他你最喜欢的工具)追踪自己和奶奶的书信往来.我偏向于使用Git作为版本控制系统(VCS),但还有其他 ...
- hdu6537 /// DP 最长不降子序列->最长公共子序列
题目大意: 给定一个字符串 字符为0~9 求翻转某个区间后使得串中的最长不降子序列最长 因为字符范围为0~9 假设有一个 0 1 2 3 4 5 6 7 8 9 的序列 此时翻转某个区间得到形如 0 ...
- C语言指针和字符串
#include <stdio.h> int main() { /********************************************* * 内存: * 1.常量区 * ...