原题链接:https://codeforces.com/problemset/problem/327/A

题意:问选择区间反转一次之后序列中最大还有多少的1?

解题思路:此题我们需要遍历序列统计最大值,一定要记得清楚负数的状态,且若我们遍历序列发现序列中翻转得到最大值为0,说明全为1,那么我们得对我们的结果减1.

AC代码:

/*
*邮箱:2825841950@qq.com
*blog:https://blog.csdn.net/hzf0701
*注:代码如有问题请私信我或在评论区留言,谢谢支持。
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<cstring>
#include<map>
#include<iterator>
#include<list>
#include<set>
#include<functional>
#include<memory.h>//低版本G++编译器不支持,若使用这种G++编译器此段应注释掉
#include<iomanip>
#include<vector>
#include<cstring>
#define scd(n) scanf("%d",&n)
#define scf(n) scanf("%f",&n)
#define scc(n) scanf("%c",&n)
#define scs(n) scanf("%s",n)
#define prd(n) printf("%d",n)
#define prf(n) printf("%f",n)
#define prc(n) printf("%c",n)
#define prs(n) printf("%s",n)
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
const ll inf = 0x3f3f3f3f;//无穷大
const ll maxn = 1e5;//最大值。
//*******************************分割线,以上为代码自定义代码模板***************************************//int n;
int nums[102];
int main(){//freopen("in.txt", "r", stdin);//提交的时候要注释掉ios::sync_with_stdio(false);//打消iostream中输入输出缓存,节省时间。cin.tie(0); cout.tie(0);//可以通过tie(0)(0表示NULL)来解除cin与cout的绑定,进一步加快执行效率。int sum,maxx,cnt;while(cin>>n){sum=0;cnt=0;maxx=0;rep(i,1,n){cin>>nums[i];if(nums[i]==1)cnt++;}rep(i,1,n){if(nums[i]==1){sum-=1;if(sum<0)//避免用小值来消sum=0;}else{sum++;if(sum>maxx)maxx=sum;}}if(maxx==0)cout<<cnt-1+maxx<<endl;elsecout<<cnt+maxx<<endl;}return 0;
}

A. Flipping Game(思维)Codeforces Round #191 (Div. 2)相关推荐

  1. 贪心 Codeforces Round #191 (Div. 2) A. Flipping Game

    题目传送门 1 /* 2 贪心:暴力贪心水水 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cs ...

  2. Codeforces Round #191 (Div. 2) A. Flipping Game【*枚举/DP/每次操作可将区间[i,j](1=i=j=n)内牌的状态翻转(即0变1,1变0),求一...

    A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. Codeforces Round #191 (Div. 2)

    好久没写过CF的博客了,最近忙着考试,各种不顺,没想到这次CF却是很顺利. A题暴力,开始看错题了..然后发现只需要转一次...B题也是暴力去构造的,C题一个组合问题,话说这次终于在比赛里把组合题给A ...

  4. Codeforces Round #191 (Div.2) 题解

    A B C D E 这场打的很爽,题目质量很高. A 给一个01序列,能将一个子串取反,求整个序列的最多1的个数. 数据范围很小,暴力枚举所有子串取反,求最大的值即可. #include<bit ...

  5. Codeforces Round #459 (Div. 2) C 思维,贪心 D 记忆化dp

    Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串. 给出一个字符串,有 (.). ? 三种字符, ? 可以 ...

  6. Codeforces Round #731 (Div. 3) G. How Many Paths? dfs + 拓扑 + 思维

    传送门 题意: 给你一张nnn个点mmm条边的图,让你对每个点确定一个编号,规则如下: (1)(1)(1) 对于不能到的点编号为000. (2)(2)(2) 对于只有一条路径能到这个点的点编号为111 ...

  7. Codeforces Round #594 (Div. 2) C. Ivan the Fool and the Probability Theory 思维 + dp

    文章目录 题意: 思路 题意: 思路 一开始找规律,表都打好了,没找出来.. 找规律还是适合让队友来. 先考虑第一行,我们先计算第一行的方案数,设f[i][j]f[i][j]f[i][j]表示到了ii ...

  8. Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table 思维 + 公式

    传送门 文章目录 题意: 思路: 题意: 给你一个n∗nn*nn∗n的矩阵,每个位置由ai∗aja_i*a_jai​∗aj​得来,主对角线为000,让你求出来aia_iai​. n≤1e3n\le1e ...

  9. Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian 数学 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一个无限个点的坐标轴,一个集合BBB,如果存在∣i−j∣=bk|i-j|=b_k∣i−j∣=bk​的话,那么i,ji,ji,j之间就连边.现在问你至少要从 ...

最新文章

  1. 超简单的网页选项卡---jQuery
  2. Linux查看进程的线程信息
  3. PAT甲级1038 Recover the Smallest Number (30 分):[C++题解]贪心、排列成最小的数、字符串
  4. 第15章习题解答(一)——《x86汇编语言:从实模式到保护模式》读书笔记40
  5. iOS开发:iPhone6、6 plus适配
  6. linux 防火墙 限速,linux iptables限速及限制每IP连接数
  7. python可变序列_python序列中可变数据类型有什么
  8. 错误的日志可能会导致疯狂;好日志可能会成为魔杖
  9. 驱动兼容_【重磅】上海数明发布国内首款兼容光耦隔离式单通道栅极驱动器系列产品SLM34x...
  10. NUC1100 Biorhythms【中国剩余定理】
  11. windows 7 局域网文件(夹)共享方法
  12. html如何判断ie版本,在html中判断IE浏览器的版本
  13. 大数据的IT分析工具
  14. 数据库技术与应用习题2
  15. bitcoin轻钱包之SPV验证
  16. win10一直显示无网络连接到服务器,win10的网络为什么会有时显示无法连接到internet...
  17. 编译时出现stripped of unavailable superclass
  18. 【清华集训2014】【BZOJ3811】玛里苟斯
  19. 透析Spring(一): Spring之IoC容器理解
  20. python-比较两个文件交集、并集、差集

热门文章

  1. Python urllib.urlencode
  2. centos6.9 yum安装中出现Loading mirror speeds from cached hostfile No package......
  3. Ubuntu GNOME插件
  4. GIS地图坐标系转换方法,快快收藏
  5. ReactNative ./gradlew assembleRelease打包失败Duplicate file
  6. python操作无界面的chrome浏览器(转)
  7. 《Cortex-CM3权威指南》——Cortex-CM3基础
  8. ONES × 中国信通院《中国企业软件研发管理白皮书》即将发布 | 预约直播
  9. 网络舆情数据汇总统计的方法技巧
  10. 快速发表论文的技巧有哪些