题目链接

给你一串只有0和1的数字,然后对某一区间的数翻转1次(0变1 1变0),只翻转一次而且不能不翻转,然后让你计算最多可能出现多少个1。

这里要注意很多细节 比如全为1,要求必须翻转,这时候我们只要翻转一个1就可以了,对于其他情况,我们只要计算区间里面如果0多于1,将其翻转后计算1的总数,然后取最大值。

//cf 191 A
//2013-07-04-22.13
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[105]; int cnt[105]; int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
int sum = 0;
memset(cnt, 0, sizeof(cnt));
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
if (a[i] == 0)
{
cnt[i] = cnt[i-1] + 1;
}
else
{
cnt[i] = cnt[i-1];
sum++;
}
}
if (sum == n)
{
printf("%d\n", sum - 1);
continue;
}
if (sum == n-1)
{
printf("%d\n", n);
continue;
}
int ans = sum + 1;
for (int i = 2; i <= n; i++)
{
for (int j = 1; j < i; j++)
{
if ((cnt[i] - cnt[j-1]) > ((i-j+1) - (cnt[i] - cnt[j-1])))
ans = max (ans, sum - ((i-j+1) - (cnt[i] - cnt[j-1])) + (cnt[i] - cnt[j-1]));
}
}
printf("%d\n", ans);
}
return 0;
}

codeforces 327 A Ciel and Dancing的更多相关文章

  1. codeforces 322 A Ciel and Dancing

    题目链接 题意: 有n个男孩和m个女孩,他们要结对跳舞,每对要有一个女孩和一个男孩,而且其中一个要求之前没有和其他人结对,求出最大可以结多少对. 如图,一条线代表一对,只有这样三种情况. #inclu ...

  2. CF 322A Ciel and Dancing 好简单的题。。最喜欢水题了

    A. Ciel and Dancing time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #190 DIV.2 A. Ciel and Dancing

    #include <cstdio> #include <iostream> #include <vector> using namespace std; int m ...

  4. 网络流(费用流)CodeForces 321B:Ciel and Duel

    Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: ...

  5. CodeForces - 321E:Ciel and Gondolas (四边形不等式优化DP)

    题意:N个人排成一行,分成K组,要求每组的不和谐值之和最小. 思路:开始以为是斜率优化DP,但是每个区间的值其实已经知道了,即是没有和下标有关的未知数了,所以没必要用斜率. 四边形优化. dp[i][ ...

  6. CodeForces 321 A - Ciel and Robot

    [题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...

  7. codeforces 327 B. Hungry Sequence

    题目链接 题目就是让你输出n个数的序列,要保证该序列是递增的,并且第i个数的前面不能保护它的约数,我直接先对前100000的素数打表,然后输出前n个,so easy. //cf 191 B #incl ...

  8. codeforces 322 B Ciel and Flowers

    题目链接 有红绿蓝三种颜色的画,每种拿三朵可以组成一束花,或者各拿一朵组成花束,告诉你每种花的数目,求出可能组成最多的花束. 如果你的代码过不了,考虑一下 8 8 9这种组合.  因为数据量很大,我的 ...

  9. Codeforces Round #190 (Div. 1 + Div. 2)

    A. Ciel and Dancing 模拟. B. Ciel and Flowers 混合类型的数量只能为0.1.2,否则3个可以分成各种类型各自合成. C. Ciel and Robot 考虑一组 ...

随机推荐

  1. Spring ——表达式语言 Spring Expression Language (转载)

    目录 SpEL简介与功能特性 一.为什么需要Spring表达式语言 二.SpEL表达式Hello World! 三.SpEL表达式 3.1.文字表达式 3.2.SPEL语言特性 3.2.1.属性 3. ...

  2. tomcat 启动窗口 名称 中文乱码

  3. VM虚拟机 VMWare Workstation Pro v15.0.1 中文破解版

    虚拟机软件VMware Workstation Pro 15.0 全新版本发布,此次更新了诸多客户机操作系统版本,另外完全兼容Win10创意者更新支持.12.0之后属于大型更新,专门为Win10的安装 ...

  4. JAVA接口的继承与集合

    复习 20190701 接口补充 一. java是单继承多实现 单继承: 一个类只能有一个父类 public class D extends D1 { } 2. 多实现 一个类可以同时实现多个接口 当 ...

  5. Python 3.5学习笔记(第一章)

    本章内容: 1.安装python 3.5 和 PyCharm 社区版 2.第一个python程序 3.变量 4.字符编码 5.用户输入 6.字符串格式化输出 7.if .else .elif 8.fo ...

  6. Lucene05-分词器

    Lucene05-分词器 1.概念 Analyzer(分词器)的作用是把一段文本中的词按规则取出所包含的所有词.对应的是Analyzer类,这是一个抽象类,切分词的具体规则是由子类实现的,所以对于不同 ...

  7. python基础知识五 各类型数据方法补充,转换,分类,编码+坑中菜

    3.9各类型数据方法补充,转换,分类,编码,坑中菜 3.9.1数据类型方法补充 1.str:不可变 补充方法 s1.capitalize():首字母大写 s1 = "alex" s ...

  8. 洛谷 P2671 求和

    题目描述 一条狭长的纸带被均匀划分出了nn个格子,格子编号从11到nn.每个格子上都染了一种颜色color\_icolor_i用[1,m][1,m]当中的一个整数表示),并且写了一个数字number\ ...

  9. 洛谷P1033 自由落体 题解

    题目链接:https://www.luogu.org/problemnew/show/P1033 呵呵,真的学好物理比较重要,前些年卡在这题上的我今天终于会做了,可恶的自由落体(也许是我太弱了吧 ) ...

  10. Error:too many padding sections on bottom border.

    异常信息: Error:too many padding sections on bottom border. 原因: 使用andoridstudio制作.9图错误. 解决 只怪我把线画多了. 修改后 ...