链接:https://codeforces.com/contest/1137


A - Skyscrapers

题解:对于每一段 $1$ 和每一段 $2$,统计他们的长度。因此对于相邻的两段长度求较小值,就有可能成为答案,维护所有的可能是答案的最大值即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int n,t[maxn];
int l1,l2;
int main()
{
cin>>n;
for(int i=;i<=n;i++) scanf("%d",&t[i]); l1=l2=;
vector<int> v;
for(int i=;i<=n;i++)
{
if(t[i]==) l1++, l2=;
if(t[i]==) l2++, l1=; if(i==n || t[i]!=t[i+])
{
if(l1>) v.push_back(l1);
if(l2>) v.push_back(l2);
}
} int ans=;
for(int i=;i<v.size()-;i++)
{
if(min(v[i],v[i+])>ans) ans=min(v[i],v[i+]);
}
cout<<*ans<<endl;
}

B - Circus - [暴力]

题解:

统计四种人的数目,$A=cnt(0,0), B=cnt(1,0), C=cnt(0,1), D=cnt(1,1)$,第一个代表是否会演小丑,第二个代表是否会演杂技。

设第一组中的三种人的数目 $cnt(1,0) = x, cnt(0,1) = C - y, cnt(1,1) = z$,因此会有等式 $x + z = y + (D-z)$,因此只需要枚举 $x,z$ 就能计算出 $y$。

然后只需要判断一下 $y \ge 0, C-y \ge 0$,以及 $n - [x+(C-y)+z] - [(B-x)+y+(D-z)] = A$ 就行了。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e3+;
int n;
char c[maxn],a[maxn];
int A,B,C,D;
vector<int> t[][];
int x,y,z;
bool check()
{
for(x=;x<=B;x++)
{
for(z=;z<=D;z++)
{
y=x+z-D+z;
if(y< || C-y<) continue;
if(x+(C-y)+z>n/ || (B-x)+y+(D-z)>n/) continue;
if(n/-(x+(C-y)+z) + n/-((B-x)+y+(D-z)) == A)
{
return ;
}
}
}
return ;
}
int main()
{
cin>>n;
scanf("%s",c+);
scanf("%s",a+); A=B=C=D=;
t[][].clear(), t[][].clear(), t[][].clear(), t[][].clear();
for(int i=;i<=n;i++)
{
if(c[i]=='' && a[i]=='') A++, t[][].push_back(i);
if(c[i]=='' && a[i]=='') B++, t[][].push_back(i);
if(c[i]=='' && a[i]=='') C++, t[][].push_back(i);
if(c[i]=='' && a[i]=='') D++, t[][].push_back(i);
} if(check()==) cout<<"-1\n";
else
{
// cout<<(n/2-(x+(C-y)+z))<<endl;
// cout<<x<<endl;
// cout<<C-y<<endl;
// cout<<z<<endl; for(int i=;i<n/-(x+(C-y)+z);i++) printf("%d ",t[][][i]);
for(int i=;i<x;i++) printf("%d ",t[][][i]);
for(int i=;i<C-y;i++) printf("%d ",t[][][i]);
for(int i=;i<z;i++) printf("%d ",t[][][i]);
}
}

C - Skyscrapers - [离散化]

题意:

有个 $n$ 条横向街道,$m$ 条纵向街道,它们产生 $nm$ 个交点,每个交点上有一栋大楼高度 $h[i][j]$。

然后你对每个交点,你要把 $[1,x]$ 的整数重新赋值给这个十字上的所有大楼。使得,一条道路上任意两栋大楼之间的高度关系都与原来一致。

题解:

离散化裸题。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n,m;
int h[][];
vector<int> r[],c[];
int main()
{
ios::sync_with_stdio();
cin.tie(), cout.tie(); cin>>n>>m;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
cin>>h[i][j]; for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++) r[i].push_back(h[i][j]);
sort(r[i].begin(),r[i].end());
r[i].erase(unique(r[i].begin(),r[i].end()),r[i].end());
}
for(int j=;j<=m;j++)
{
for(int i=;i<=n;i++) c[j].push_back(h[i][j]);
sort(c[j].begin(),c[j].end());
c[j].erase(unique(c[j].begin(),c[j].end()),c[j].end());
} for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
int tp1=lower_bound(r[i].begin(),r[i].end(),h[i][j])-r[i].begin();
int tp2=lower_bound(c[j].begin(),c[j].end(),h[i][j])-c[j].begin();
int tp3=r[i].end()-lower_bound(r[i].begin(),r[i].end(),h[i][j]);
int tp4=c[j].end()-lower_bound(c[j].begin(),c[j].end(),h[i][j]);
printf("%d ",max(tp1,tp2)+max(tp3,tp4));
}
printf("\n");
}
}

D - Cooperative Game - [交互题+思维题]

Codeforces 1138 - A/B/C/D/E - (Undone)的更多相关文章

  1. Codeforces 785 - A/B/C/D/E - (Undone)

    链接:https://codeforces.com/contest/785 A - Anton and Polyhedrons #include<bits/stdc++.h> using ...

  2. Codeforces 677 - A/B/C/D/E - (Undone)

    链接: A - Vanya and Fence - [水] AC代码: #include<bits/stdc++.h> using namespace std; ; int n,h; in ...

  3. Codeforces 1062 - A/B/C/D/E - (Undone)

    链接:http://codeforces.com/contest/1062 A - Prank - [二分] 题意: 给出长度为 $n(1 \le n \le 100)$ 的数组 $a[1 \sim ...

  4. Codeforces 1032 - A/B/C/D/E - (Undone)

    链接:http://codeforces.com/contest/1032/ 是真的真的真的忍不住想吐槽这题意是真的真的真的读不懂…… A - Kitchen Utensils - [简单数学题] 题 ...

  5. Codeforces 1154 - A/B/C/D/E/F/G - (Undone)

    链接:https://codeforces.com/contest/1154 A - Restoring Three Numbers - [水] #include<bits/stdc++.h&g ...

  6. Codeforces 1114 - A/B/C/D/E/F - (Undone)

    链接:http://codeforces.com/contest/1114 A - Got Any Grapes? 题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄.紫葡萄和黑葡萄,甲乙丙三个人至少要 ...

  7. Codeforces 1043 - A/B/C/D/E/F - (Undone)

    链接:http://codeforces.com/contest/1043 A - Elections - [水水水水题] 题意: 我和另一个人竞争选举,共有 $n$ 个人投票,每个人手上有 $k$ ...

  8. Codeforces 659 - A/B/C/D/E/F/G - (Undone)

    链接:https://codeforces.com/contest/659 A - Round House - [取模] AC代码: #include<bits/stdc++.h> usi ...

  9. Codeforces 1132 - A/B/C/D/E/F - (Undone)

    链接:http://codeforces.com/contest/1132 A - Regular Bracket Sequence - [水] 题解:首先 "()" 这个的数量多 ...

随机推荐

  1. 让rpc支持双向通信

    rpc采用了C/S模型,不支持双向通信:client只能远程调用server端的RPC接口,但client端则没有RPC供server端调用,这意味着,client端能够主动与server端通信,但s ...

  2. FFmpeg中的时间基(time_base), AV_TIME_BASE

    AV_TIME_BASE 经常在FFmpeg的代码中看到一个奇怪的单位 AV_TIME_BASE ,比如 AVFormatContext 结构体中就有这样一个字段: duration ,它在FFmpe ...

  3. 【Zookeeper】连接ZooKeeper的方式

    使用客户端命令连接Zookeeper 连接Server 使用命令./zkCli.sh -server 127.0.0.1:2181 使用JAVA连接使用ZK POM添加引用 <dependenc ...

  4. 【Java】设计模型-五种单例模型

    一. 什么是单例模式 只需要某个类同时保留一个对象,不希望有更多对象,此时,我们则应考虑单例模式的设计. 单例模式的主要作用是保证在Java程序中,某个类只有一个实例存在. 单例模式有很多好处,它能够 ...

  5. [转]application.properties详解 --springBoot配置文件

    本文转载:http://blog.csdn.net/lpfsuperman/article/details/78287265###; # spring boot application.propert ...

  6. gsoap入门:C/C++代码生成及编译--包含soapcpp2 -qname添加命名空间后报错的解决方法--可用

    gsoap是什么 先来一段百度百科,说说gsoap是什么: gSOAP一种跨平台的开源的C/C++软件开发工具包.生成C/C++的RPC代码,XML数据绑定,对SOAP Web服务和其他应用形成高效的 ...

  7. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error com piling: 无效的标记: -parameters

    背景:本项目使用JDK1.8 编译maven工程的时候出现如下错误: Failed to execute goal org.apache.maven.plugins:maven-compiler-pl ...

  8. count(1)、count(*)与count(列名)的执行区别

    执行效果: 1.  count(1) and count(*) 当表的数据量大些时,对表作分析之后,使用count(1)还要比使用count(*)用时多了! 从执行计划来看,count(1)和coun ...

  9. 智能聊天机器人——基于RASA搭建

    前言: 最近了解了一下Rasa,阅读了一下官方文档,初步搭建了一个聊天机器人. 官方文档:https://rasa.com/docs/ 搭建的chatbot项目地址: https://github.c ...

  10. 三、Sql Server 基础培训《进度3-是否使用外键(知识点学习)》

    学习作业3: 问题1:你觉得外键有哪些适用情况?哪些不适用情况?   问题2:本次实战案例,由你来架构,你觉得有必要建立外键吗? 说明你的理由?     ======================= ...