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. Json---Windows下使用Jsoncpp

    上述Json解析使用的是Jsoncpp,要使用Jsoncpp,得做如下几步的配置: 1. 首先从http://sourceforge.net/projects/jsoncpp/下载,压缩包大约105k ...

  2. ubuntu下使用sublime text进行C编程开发尝鲜

    1 选择编译系统 2 编写文件,编译(Ctrl+B)运行(Shift+Ctrl+B)

  3. UVA 1203 - Argus(优先队列)

    UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次 ...

  4. Android NDK开发-2-环境搭建

    1.环境变量配置NDK 2.选中项目,右键属性菜单,创建一个新的编译器

  5. linux命令之find和locate

    1.find / -name  log.xml   按照名字查找log.xml文件 2.locate log.xml     查找log.xml文件(效率高) 3.grep 'hive'  word. ...

  6. 【RF库Collections库测试】关键字append to list

    Arguments:[ list_ | *values ]Adds `values` to the end of `list`.

  7. hasattr() 、getattr() 、setattr()

    hasattr(object, name) :用于判断一个对象中是否有指定的属性或方法,如果存在返回 True,否则返回 False getattr(object, name, [default]) ...

  8. ubuntu系统无eth0网卡解决办法

    ubuntu终端下命令ifconfig的问题解决 问题一. ifconfig之后只显示lo,没有看到eth0 问题二. ifconfig之后显示eth0,但是没有显示静态IP地址,即无inet.地址. ...

  9. linux系统usb挂载

    本次例程的环境是在FC6下,通过终端操作的. 注意要挂载U盘需要有管理员的权限. 切换成管理员,输入: su root 然后输入管理员密码,进行密码认证: 成功后,先在 /mnt 下建立一个名叫USB ...

  10. (一)微信小程序之模拟调用后台接口踩过的坑

    如下图标记的三个点 在调试过程中出现问题,特此记录. 1. 之前在浏览器测试接口习惯省略 http:// ,是因为浏览器默认有一个检测,在你输入的网址前面加http://,如果有就不加. 然而在微信小 ...