A. Curriculum Vitae

题目链接:http://codeforces.com/contest/846/problem/A

题目意思:给你一个只包含0-1的数组,现在要求去可以去掉一些元素使得不会出现10子串,并且剩下的元素还要最大,输出剩下元素的数量。

题目思路:由于0不可能出现1的后面所以,最后出现必定是000011111,这样的串,所以我们暴力枚举每一位k,设a={1,2,3……,k-1}中0的数量,b=(k+1,k+2,…………n}中1的数量,这样tmp=a+b+1,那么ans=max(tmp);

代码:

 /* ***********************************************
Author :xiaowuga
Created Time :2017年10月04日 星期三 09时19分12秒
File Name :A.cpp
************************************************ */
#include <bits/stdc++.h>
#define mem(s,ch) memset(s,ch,sizeof(s))
typedef long long LL;
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie();
int n;
int a[];
cin>>n;
for(int i=;i<n;i++) cin>>a[i];
int ans=;
for(int i=;i<n;i++){
int t=;
for(int j=;j<n;j++){
if(j<i&&!a[j]) t++;
if(j>i&&a[j]) t++;
}
ans=max(ans,t+);
}
cout<<ans<<endl;
return ;
}

B. Math Show

题目链接:http://codeforces.com/contest/846/problem/B

题目意思:现在有n个任务每个任务有k个子任务,完成一个任务可以得到一份,每完成一个任务的所有子任务,可以额外获得一分,所有任务的子任务同一下标的子任务都有一样的花费时间,但是不同子任务的花费时间可能是不一样的,现在有M的时间,求在M时间内可以获得最大的得分是多少?

题目思路:我们发现n比较小,最大只有45,所以我们可以暴力枚举完成了多少个大任务,剩下的时间,根据尽量先完成花费时间少的子任务,然后维护最大的得分。

代码:

 /* ***********************************************
Author :xiaowuga
Created Time :2017年10月04日 星期三 09时54分31秒
File Name :B.cpp
************************************************ */
#include <bits/stdc++.h>
#define mem(s,ch) memset(s,ch,sizeof(s))
typedef long long LL;
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie();
int n,k;
LL M;
LL a[];
LL sum=;
cin>>n>>k>>M;
for(int i=;i<k;i++) {
cin>>a[i];
sum+=a[i];
}
sort(a,a+k);
int ans=;
for(int i=;i<=n;i++){
LL t=sum*i;
int tmp=i*k+i;
if(t>M) break;
t=M-t;
for(int j=;j<k;j++){
for(int p=;p<=n-i;p++){
if(t>=a[j]){
t-=a[j];
tmp++;
}
else{
j=k;break;
}
}
}
ans=max(ans,tmp);
}
cout<<ans<<endl;
return ;
}

C. Four Segments

题目链接:http://codeforces.com/contest/846/problem/C

题目意思:现在有一个数列p包含n个元素,然后现在要找到三个分割点a,b,c(表示下标)使得ans=sum(0,a)-sum(a,b)+sum(b,c)-sum(c,n),数组下标从1开始,sum(x,y)表示(p[x+1],p[x+2],p[x+3],p[x+4]…………+p[y])的和,现在要是ans最大,请输出这a,b,c这三个下标,abc可以相等表示区间为空。

题目思路:前缀和处理这个是肯定的,然后朴素的想法就是暴力n^3去枚举abc的位置,然后求最大值,但是明显对于题目数据这个复杂度太大了。我们需要把有他优化成n^2,一个简单的想法我们可以枚举a和c,然后对a,c这个区间我们寻去一个pos,使得sum(a,pos)最小,则sum(pos,b)就会最大,因为sum(a,c)对于确定的ac是不会变的,我们知道sum(a,pos)=presum[pos]-presum[a],枚举时候presum[a]已经确定了,所以我们我们只需要是presum[pos]尽量小,就可以了。这样暴力的扫一遍维护一个最大值就可以得到答案了。

代码:

 /* ***********************************************
Author :xiaowuga
Created Time :2017年10月04日 星期三 11时02分34秒
File Name :C.cpp
************************************************ */
#include <bits/stdc++.h>
#define mem(s,ch) memset(s,ch,sizeof(s))
typedef long long LL;
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
LL dp[]={};
LL sum(int l,int r){
return dp[r]-dp[l];
}
int main(){
ios::sync_with_stdio(false);cin.tie();
int n;
cin>>n;
for(int i=;i<=n;i++){
LL t;
cin>>t;
dp[i]=dp[i-]+t;
}
LL ans=-1e15,a,b,c;
for(int i=;i<=n;i++){
LL k=dp[i],pos=i;
for(int j=i;j<=n;j++){
if(dp[j]<k){
k=dp[j]; pos=j;
}
LL cur=sum(,i)-sum(i,pos)+sum(pos,j)-sum(j,n);
if(ans<cur){
ans=cur;
a=i,b=pos,c=j;
}
}
}
cout<<a<<' '<<b<<' '<<c<<endl;
return ;
}

D. Monitor

题目链接:http://codeforces.com/contest/846/problem/D

题目意思:现在有一个显示器,有n×m个像素点,最后会有q点是坏掉的,每个点给出三个参数x,y,t,表示坐标为(x,y)的点在t时刻以后(包括t时刻)都是坏掉的,询问是否存在一个k×k的矩形区域内都是坏掉的点,如果不存在输出-1,如果存在输出第一个出现这样坏掉的矩形出现时刻。

题目思路:二维前缀和+二分(可能有人用的是什么二维树状数组,但是不会啊,只会暴力啊,不会高端数据结构),直接看代码吧!很暴力的思想,每次二分处理一下二维前缀和,然后n^2验证。

代码:

 /* ***********************************************
Author :xiaowuga
Created Time :2017年10月04日 星期三 13时50分59秒
File Name :D.cpp
************************************************ */
#include <bits/stdc++.h>
typedef long long LL;
#define endl "\n"
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
int M[][]={};
int mt;
int n,m,k,q;
struct node{
int x,y,t;
bool operator <(const node &x) const{
return t<x.t;
}
};
vector<node>a;
int solve(int i,int j){
return M[i][j]-M[i-k][j]-M[i][j-k]+M[i-k][j-k];
}
void AC(){
int l=,r=1e9+;
while(l<r){
int md=l+(r-l)/;
for(int i=;i<=n;i++) for(int j=;j<=m;j++) M[i][j]=;
for(int i=;i<q;i++) if(a[i].t<=md) M[a[i].x][a[i].y]=; for(int i=;i<=n;i++) for(int j=;j<=m;j++) M[i][j]+=M[i-][j]+M[i][j-]-M[i-][j-];
int flag=;
for(int i=k;i<=n;i++){
for(int j=k;j<=m;j++){
int num=solve(i,j);
if(num==k*k){
flag=;
i=n+;
break;
}
}
}
if(flag) r=md;
else l=md+;
}
cout<<l<<endl;
}
int main(){
ios::sync_with_stdio(false);cin.tie();
mt=-;
cin>>n>>m>>k>>q;
a.resize(q);
for(int i=;i<q;i++){
cin>>a[i].x>>a[i].y>>a[i].t;
M[a[i].x][a[i].y]=;
mt=max(mt,a[i].t);
}
sort(a.begin(),a.end());
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
M[i][j]+=M[i-][j]+M[i][j-]-M[i-][j-];
}
}
int flag=;
for(int i=k;i<=n;i++){
for(int j=k;j<=m;j++){
int num=solve(i,j);
if(num==k*k){
flag=;
i=n+;
break;
}
}
}
if(flag) AC();
else cout<<-<<endl;
return ;
}

Educational Codeforces Round 28的更多相关文章

  1. D. Monitor Educational Codeforces Round 28

    http://codeforces.com/contest/846/problem/D 二分答案 适合于: 判断在t时候第一次成立 哪个状态是最小代价 #include <cstdio> ...

  2. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  5. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  8. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. 使用ffmpeg实现合并多个音频为一个音频的方法

    使用ffmpeg实现合并多个音频为一个音频的方法可以使用ffmpeg的filter功能来进行这个操作,而且效果很好amerge也可以实 使用ffmpeg实现合并多个音频为一个音频的方法 可以使用ffm ...

  2. myslq的索引类型为MyISAM和BDB的表:复合索引下的自增长

    本文源自:http://www.himigame.com/mysql/781.html 3.6.9. 使用AUTO_INCREMENT 可以通过AUTO_INCREMENT属性为新的行产生唯一的标识: ...

  3. php纯原生实现数组二分法

    代码如下 $arr = [1,3,5,7,9];//$arr = range(1,10000);var_dump(find($arr, 2)); function find(array $arr, $ ...

  4. jQuery-处理元素内容、表单元素

    处理元素内容 1.text方法 使用说明: 1)不传参数 得到jQuery对象内所有元素及其后代元素的文本内容 2)传入用于设置匹配元素的文本内容 3)传入function 使用函数来设置jQuery ...

  5. 结构型模式概述(Structural Pattern)

    结构型模式可以描述两种不同的东西:类与类的实例.结构型模式可以分为类结构型模式和对象结构型模式. 类结构型模式关心类的组合,可以由多个类组合成一个更大的系统,在类结构型模式中只存在继承关系和实现关系: ...

  6. 完美解决jQuery符号$与其他javascript 库、框架冲突的问题

    目前有大量的 javascript 开发框架,其中有一部分使用 $ 作为调用符号,这可能导致相互之间的冲突,而 jQuery 为解决这个问题,可以在 jQuery 导入时放弃 $ 使用权,届时 $ 则 ...

  7. 制作一款3D炸弹超人游戏

    说起炸弹超人,相信很多朋友都玩过类似的游戏,其中最为人熟知的莫过于<泡泡堂>.该类型游戏需要玩家在地图中一边跑动一边放置炸弹,同时还要躲避敌方炸弹保护自己.最初的炸弹超人游戏都是2D的,今 ...

  8. [extjs] extjs 5.1 API 开发 文档

    官方博客发布了这个新版本说明,英文文章请戳下面 http://www.sencha.com/blog/announcing-sencha-ext-js-5.1/ 翻译版本请戳下面: http://ex ...

  9. [转]ASP.NET MVC 5 - 给数据模型添加校验器

    在本节中将会给Movie模型添加验证逻辑.并且确保这些验证规则在用户创建或编辑电影时被执行. 拒绝重复 DRY ASP.NET MVC 的核心设计信条之一是DRY: "不要重复自己(DRY  ...

  10. 查看网卡流量:nload

    nload命令用于查看网卡流量,用法如下: [root@localhost ~]$ yum install -y epel-release [root@localhost ~]$ yum instal ...