题目链接:http://www.codeforces.com/problemset/problem/327/A
题意:你现在有n张牌,这些派一面是0,另一面是1。编号从1到n,你需要翻转[i,j]区间的牌一次,使得看到的牌是1的数量最大。
C++代码:

#include <iostream>
using namespace std;
const int maxn = ;
int n, a[maxn], sum[maxn];
int flip(int L, int R)
{
int a1 = sum[R] - sum[L-];
int a2 = R - L + - a1;
//cout << "a1=" << a1 << "; a2=" << a2 << ";[" << L << ", " << R << "] == " << sum[n] - sum[R] + sum[L-1] + a2 << endl;
return sum[n] - sum[R] + sum[L-] + a2;
}
int main()
{
cin >> n;
for (int i = ; i <= n; i ++)
{
cin >> a[i];
sum[i] = sum[i-] + a[i];
}
int ans = min(sum[n]+, n-);
for (int i = ; i <= n; i ++)
for (int j = i; j <= n; j ++)
ans = max(ans, flip(i, j));
cout << ans;
return ;
}

C++

codeforces水题100道 第二十题 Codeforces Round #191 (Div. 2) A. Flipping Game (brute force)的更多相关文章

  1. codeforces水题100道 第二十六题 Codeforces Beta Round #95 (Div. 2) A. cAPS lOCK (strings)

    题目链接:http://www.codeforces.com/problemset/problem/131/A题意:字符串大小写转换.C++代码: #include <cstdio> #i ...

  2. codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)

    题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include ...

  3. codeforces水题100道 第二十四题 Codeforces Beta Round #85 (Div. 2 Only) A. Petya and Strings (strings)

    题目链接:http://www.codeforces.com/problemset/problem/112/A题意:忽略大小写,比较两个字符串字典序大小.C++代码: #include <cst ...

  4. codeforces水题100道 第二十二题 Codeforces Beta Round #89 (Div. 2) A. String Task (strings)

    题目链接:http://www.codeforces.com/problemset/problem/118/A题意:字符串转换……C++代码: #include <string> #inc ...

  5. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)

    题目链接:http://www.codeforces.com/problemset/problem/281/A题意:将一个英文字母的首字母变成大写,然后输出.C++代码: #include <c ...

  6. codeforces水题100道 第二十三题 Codeforces Beta Round #77 (Div. 2 Only) A. Football (strings)

    题目链接:http://www.codeforces.com/problemset/problem/96/A题意:判断一个0-1字符串中出现的最长的0字串或者1字串的长度是否大于等于7.C++代码: ...

  7. codeforces水题100道 第二十一题 Codeforces Beta Round #65 (Div. 2) A. Way Too Long Words (strings)

    题目链接:http://www.codeforces.com/problemset/problem/71/A题意:将长字符串改成简写格式.C++代码: #include <string> ...

  8. codeforces水题100道 第十题 Codeforces Round #277 (Div. 2) A. Calculating Function (math)

    题目链接:www.codeforces.com/problemset/problem/486/A题意:求表达式f(n)的值.(f(n)的表述见题目)C++代码: #include <iostre ...

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

    题目传送门 /* 贪心:暴力贪心水水 */ #include <cstdio> #include <algorithm> #include <cstring> us ...

随机推荐

  1. pandas 的数据结构(Series, DataFrame)

    Pandas 讲解 Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的. Pandas 纳入了大量库和一些标 ...

  2. Android 8 声音调整过程

    记录Android 8声音调整过程. frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.j ...

  3. e826. 获得和设置JSplitPane分开的位置

    The location of a divider is measured in pixels from either the left edge (in the case of a horizont ...

  4. MYSQL之You can't specify target table for update in FROM clause解决办法

    mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...

  5. u3d资源打包只能打包场景材质,不能打包脚本

    GameObject附带脚本打包进来以后,只有一个脚本名字,估计只是关联了脚本,内容却不在,所以后面打包资源的话,一定要把脚本,shader之类的,放到工程目录下

  6. SharePoint 使用ECMAscript对象模型来操作Goup与User

    这里总结了关于使用ECMAscript对象模型来操作Goup与User的常用情况,内容如下:     1.取得当前Sharepoint网站所有的Groups     2.获取当前登录用户的Title与 ...

  7. Data Set Config配置元件

    右键点击Jmeter中需要参数化的某个请求,选择添加——配置原件——CSV Data Set Config,会添加一个CSV Data Set Config,需要设置相关的一些内容,具体如下:

  8. 服务端API安全解决方案

    由于server端和client端需要通信,所以api的安全性需要保证 1.完全开放的 一般只是查询,不能执行增.删.改的操作 裸奔的 <?php public function getGood ...

  9. Blender 界面操作

    1.旋转场景 使用鼠标中间键旋转整个场景.按住Shift键,再操作鼠标中间键则可平移整个场景. 2.数字键盘功能 数字键盘1.3.7,分别控制场景向前.向后.向上显示. 数字键盘5,可以在正射投影(O ...

  10. 什么是REST设计风格

    https://zh.wikipedia.org/wiki/REST http://www.infoq.com/cn/articles/rest-introduction