Educational Codeforces Round 28
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的更多相关文章
- D. Monitor Educational Codeforces Round 28
http://codeforces.com/contest/846/problem/D 二分答案 适合于: 判断在t时候第一次成立 哪个状态是最小代价 #include <cstdio> ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [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 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
随机推荐
- e577. Enabling Antialiasing
// See e575 The Quintessential Drawing Program public void paint(Graphics g) { // Retrieve the graph ...
- Supervision 行为模式
官方链接:http://erlang.org/doc/man/supervisor.html http://erlang.org/doc/design_principles/sup_princ.htm ...
- CentOS查看本机公网IP命令
icanhazip.com 使你在任何地方知道你的公网IP地址 icanhazip.com是一个网址,你在浏览器中输入这个网址,你就能得到你的公网IP地址了. 我在Linux下一般使用curl ica ...
- 最短路径问题-Dijkstra
概述 与前面说的Floyd算法相比,Dijkstra算法只能求得图中特定顶点到其余所有顶点的最短路径长度,即单源最短路径问题. 算法思路 1.初始化,集合K中加入顶点v,顶点v到其自身的最短距离为0, ...
- 怎样用MathType输入带分数
MathType作为一种常用的数学公式编辑器.虽然其操作已经很简单了,但是对于刚刚接触MathType的新用户来说,一些最基本的MathType输入也是有一定难度的,一些人在MathType分数的编辑 ...
- Android - Style问题
转自:http://jingyan.baidu.com/article/c910274be7536acd361d2dca.html 转自:http://blog.sina.com.cn/s/blog_ ...
- Redis(一)-- 基础
一.Redis 简介 Redis 是完全开源免费的,是一个高性能的key-value数据库. Redis 与其他 key - value 缓存产品有以下三个特点: Redis支持数据的持久化,可以将内 ...
- Qt监控Access数据库
配置文件setup.ini内容 [General] DBFilePath=C:/Users/WangGang/Desktop/Database1.accdb DBUserName= DBPasswor ...
- Java之类型的转换
1.String 类型转化为 int 类型,需要使用 Integer 类中的 parseInt() 方法或者 valueOf() 方法进行转换. int a = Integer.parseInt(st ...
- 基于Cocos2d-x学习OpenGL ES 2.0系列——初识MVP(3)
在上一篇文章中,我在介绍vertex shader的时候挖了一个坑:CC_MVPMatrix.它其实是一个uniform,每一个Cocos2d-x预定义的shader都包含有这个uniform,但是如 ...