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. java---EL与ONGL的区别

    EL表达式: >>单纯在jsp页面中出现,是在四个作用域中取值,page,request,session,application.>>如果在struts环境中,它除了有在上面的 ...

  2. (转)SDL2.0在mfc窗口中显示yuv的一种方法

    DWORD ThreadFun() {    //用mfc窗口句柄创建一个sdl window    SDL_Window * pWindow = SDL_CreateWindowFrom( (voi ...

  3. par函数cex参数-控制文字和点的大小

    cex参数用来控制图片中点和文字的大小,对于一副图片来说,有很多的文字部分,包括x轴标签(xlab), y轴标签(ylab), x轴刻度上的文字, y轴刻度上的文字,主标题(main), 副标题(su ...

  4. CentOS7设置开机自启动命令大全

    任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 httpd  on              systemctl enable httpd.service 使某服务不自 ...

  5. jQuery.ajax实现根据不同的Content-Type做出不同的响应

    使用H5+ASP.NET General Handler开发项目,使用ajax进行前后端的通讯.有一个场景需求是根据服务器返回的不同数据类型,前端进行不同的响应,这里记录下如何使用$.ajax实现该需 ...

  6. jquery+json实现分页效果

    son作为一种轻量级的数据交换格式,由于其传输数据格式的方便性,今天偶然想将其应用于分页实现,分页做为web开发一个长久的话题,其应用的高效与重要性就不多说了本文主要技术:反射机制,Json数据格式, ...

  7. 提高Web性能的前端优化技巧总结

  8. swift swift学习笔记--函数和闭包

    使用 func来声明一个函数.通过在名字之后在圆括号内添加一系列参数来调用这个方法.使用 ->来分隔形式参数名字类型和函数返回的类型 func greet(person: String, day ...

  9. 《C++ Primer Plus》第11章 使用类 学习笔记

    本章介绍了定义和使用类的许多重要方面.一般来说,访问私有类成员的唯一方法是使用类方法.C++使用友元函数来避开这种限制.要让函数称为友元,需要在类声明中声明该函数,并在声明前加上关键字friend.C ...

  10. 真 · windows环境下php7.0以上开启curl方法

    看这个说明之前,大家肯定百度在网上看到什么: 配置php.ini ,把curl_dll前的分号去掉 在php.ini中,查找extension=php_curl.dll ,找到后把它前面的分号去掉 之 ...