codeforces水题100道 第二十题 Codeforces Round #191 (Div. 2) A. Flipping Game (brute force)
题目链接: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)的更多相关文章
- codeforces水题100道 第二十六题 Codeforces Beta Round #95 (Div. 2) A. cAPS lOCK (strings)
题目链接:http://www.codeforces.com/problemset/problem/131/A题意:字符串大小写转换.C++代码: #include <cstdio> #i ...
- codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)
题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include ...
- 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 ...
- codeforces水题100道 第二十二题 Codeforces Beta Round #89 (Div. 2) A. String Task (strings)
题目链接:http://www.codeforces.com/problemset/problem/118/A题意:字符串转换……C++代码: #include <string> #inc ...
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)
题目链接:http://www.codeforces.com/problemset/problem/281/A题意:将一个英文字母的首字母变成大写,然后输出.C++代码: #include <c ...
- 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++代码: ...
- 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> ...
- 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 ...
- 贪心 Codeforces Round #191 (Div. 2) A. Flipping Game
题目传送门 /* 贪心:暴力贪心水水 */ #include <cstdio> #include <algorithm> #include <cstring> us ...
随机推荐
- 【转】【Python】Python 中文编码报错
用 Python 输出 "Hello, World!",英文没有问题,但是如果你输出中文字符"你好,世界"就有可能会碰到中文编码问题. Python 文件中如果 ...
- JUnit断言
在本节中,我们将介绍一些断言方法.所有这些方法都受到 Assert 类扩展了java.lang.Object类并为它们提供编写测试,以便检测故障.下表中有一种最常用的断言方法的更详细的解释. 断言 描 ...
- Maven POM
POM代表项目对象模型.它是 Maven 中工作的基本单位,这是一个 XML 文件.它始终保存在该项目基本目录中的 pom.xml 文件.POM 包含的项目是使用 Maven 来构建的,它用来包含各种 ...
- php 序列化与反序列化
<?php //声明一个类 class dog { var $name; var $age; var $owner; function dog($in_name=",$in_owner ...
- python3两个字典的合并
两个字典的合并其实很简单,直接用dict的update即可,代码如下: # /usr/bin/python3 # -*- encoding: utf-8 -*- ", "" ...
- QA:Initialization of bean failed; nested exception is java.lang.AbstractMethodError
Q: <hibernate.version>5.2.10.Final</hibernate.version><dependency> <groupId> ...
- CI框架 -- 核心文件 之 Hooks.php
钩子 - 扩展框架核心 CodeIgniter 的钩子特性提供了一种方法来修改框架的内部运作流程,而无需修改 核心文件.CodeIgniter 的运行遵循着一个特定的流程,你可以参考这个页面的 应用程 ...
- Blog
http://www.cnblogs.com/digdeep/archive/2015/11/16/4968453.htmlhttp://it.dataguru.cn/article-8406-1.h ...
- MySQL 数据库定时自动备份
创建备份目录 cd /home mkdir backup cd backup 创建备份 Shell 脚本: vim DatabaseName.sh #!/bin/bash /usr/local/mys ...
- HTTP常见的Post请求
零.HTTP协议是什么样的? HTTP的请求报文分为三部分:请求行.请求头.请求体 如下2张图表示的意思一致: 图一 图二 本文章的重点是请求体(请求数据),请求行和请求头的部分请参考: http ...