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. Wellner 自适应阈值二值化算法

    参考文档: Adaptive Thresholding for the DigitalDesk.pdf       Adaptive Thresholding Using the Integral I ...

  2. bootstrap -- css -- 图片

    图片样式 .img-rounded:添加 border-radius:6px 来获得图片圆角 .img-circle:添加 border-radius:500px 来让整个图片变成圆形. img-ci ...

  3. R语言低级绘图函数-title

    title 函数用来在一张图表上添加标题 基本用法: main 表示主标题,通常位于图像的上方, sub 表示副标题,位于图像的下方, xlab 表示x轴的标签,ylab 表示y轴的标签 par(om ...

  4. linux下常用FTP命令 1. 连接ftp服务器

    1. 连接ftp服务器 格式:ftp [hostname| ip-address] a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密 ...

  5. 安装 oracle [转]

    先下载3个东西:链接忘记了,大家自己找一下 1  ORA+11+G+R2+server+64bit+for+windows.iso  (Oracle 安装文件) 2  PLSql 3  oracle6 ...

  6. 如何用ChemDraw建立多中心结构

    通过调整ChemDraw多中心机构的连接可绘制有意义的络合物结构,建立中心原子和络合配体后,利用多中心化学键连接上述结构即可.以下内容将具体介绍如何用ChemDraw建立多中心结构. 一.多中心键和多 ...

  7. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto

    控制台: 2016-4-1 16:32:06 org.hibernate.annotations.common.Version <clinit> 信息: Hibernate Commons ...

  8. MVC3--View层

    Razor二义性: 1,当view层中出现   邮件格式时候比如   anbylau2130@qq.com 这种情况Razor将会出现多义性 可以使用@@来转义为一个@字符, 如:<p>y ...

  9. Android:控件布局(相对布局)RelativeLayout(转)

    相对布局常用属性: 子类控件相对子类控件:值是另外一个控件的id android:layout_above----------位于给定DI控件之上android:layout_below ------ ...

  10. VR室内定位系统小结

    一.写在开始之前 不管是HTC 的Vive还是OC的CV1,都说明VR 定位设备和手柄都会成为未来VR的发展趋势. VR目前关键就是体验,全身心的投入,身临其境的感觉. 不能总玩着玩着,出戏了.这肯定 ...