链接: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. docker占满linux磁盘根目录的解决办法

    一.磁盘根目录被占满 [test@localhost docker]$ df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/ce ...

  2. 洛谷 P1162 填涂颜色

    题目链接:https://www.luogu.org/problemnew/show/P1162 题目描述由数字0组成的方阵中,有一任意形状闭合圈,闭合圈由数字1构成,围圈时只走上下左右4个方向.现要 ...

  3. kuda 了解片

    本来上个月想去了解一下kuda的,结果一直没有抽出时间去搞,现在大致先开个头,方便后面深入! Apache Kudu是开源Apache Hadoop生态系统的新成员,它完善了Hadoop的存储层,可以 ...

  4. (七):处理MFC

    (一):简单介绍 为了可以在一个Winelib应用中使用MFC,你须要首先使用Winelib又一次编译MFC. 在理论上,你应该为Windows的MFC编写一个封装(怎样编写在后面介绍).可是,在实践 ...

  5. 【20171123】【GITC精华演讲】贝业新兄弟李济宏:如何做到企业信息化建设的加减乘除

    导读 11月23日智慧物流论坛上,贝业新兄弟李济宏分享了<如何做到企业信息化建设的加减乘除>演讲,介绍了如何更好的构建企业信息化系统. 30秒get演讲干货 为什么用户总说系统难用?为什么 ...

  6. 关于Java 软件工程师应该知道或掌握的技术栈

    鄙人星云,今天突然想写这么一篇需要持续更新的文章,主要目的用于总结当前最流行的技术和工具,方便自己也方便他人. 更新时间:2018-10-23 09:26:19 码农职业路径图 码农入门职业路径图 J ...

  7. idea 配置 maven 项目

    maven 项目  用模块引入进来 1.引入  pom.xml 2.如果不是web则要添加web支持 3.配置资源  类  和依赖  and 项目语言环境 5.配置  artifacts 部署   w ...

  8. java语言的优缺点

    转载自:https://blog.csdn.net/bingshanyijiao_fkx/article/details/51613954 角度一: 优点:简单.安全.稳定.跨平台 缺点:需要运行环境 ...

  9. rm -rf python 实现 v0.1

    #coding=utf- import os def join(arr,join_falg): res = "" for a in arr: res += a+join_falg ...

  10. Deepin 系统下安装VMware并激活

    1.打开深度商店:搜索VMware,并下载安装. 2.打开启动器:点击VMware-install. 3.填写管理员密码. 4.下一步,完成安装. 5.打开VMware Workstation,输入密 ...