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 ...
随机推荐
- Tornado + Celery + RabbitMQ
声明:代码是从项目中截取的, 为进行测试 使用Celery任务队列,Celery 只是一个任务队列,需要一个broker媒介,将耗时的任务传递给Celery任务队列执行,执行完毕将结果通过broker ...
- 在Ubuntu14.04上编译Android4.0.1出现的几个问题
一. 工具 sudo apt-get install git-core gnupg flex bison gperf build-essential \ zip curl libc6-de ...
- android位移动画的两种实现方式
在android开发,我们会常常使用到位移动画,普通情况下位移动画有两种实现方式.一种是直接通过java代码去实现,第二种是通过配置文件实现动画,以下是两种动画的基本是用法: 纯Java代码实现: / ...
- js jquery 按钮点击后 60秒之后才能点击 60秒倒计时
var wait = 60; function time(o) { if (wait == 0) { $(o).attr("disabled", false); $(o).val( ...
- 如何找回Ucenter创始人密码,账号无需修改
UCenter 创始人的密码非常重要,忘记或丢失后,就不能进入 UCenter 进行用户和数据的管理,也会对站点造成安全隐患.由于 UCenter 的密码是采用两次 md5 加一个随机数的形式加密的, ...
- 阿里云mysql远程连不上
1. 服务器规则添加 3306端口 2. mysql localhost 改为% mysql> select user, host from mysql.user; GRANT ALL PRIV ...
- lakala反欺诈建模实际应用代码GBDT监督学习
/** * Created by lkl on 2018/1/16. */ import org.apache.spark.mllib.evaluation.BinaryClassificationM ...
- winform c#中子窗体关闭刷新父窗体
父窗体Form1 子窗体Form2 Form1中有一个datagridview控件和一添加按钮,Form2中有一个Text控件和一个保存按钮 要求点击Form1窗体上的添加按钮,弹出Form2,再te ...
- 【spark】jieba + wordcount
import sys reload(sys) sys.setdefaultencoding('utf-8') from os import path import jieba from pyspark ...
- python中的List 和 Tuple
#-*- coding:UTF-8 -*- classmates=["Michael","Bob","Tracy"] print(class ...