链接: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. linux服务器挂掉自动重启脚本(转)

    实现原理主要是使用linux提供的crontab机制,定时查询服务器进程是否存在,如果宕机则执行我们预设的重启脚本. 首先我们要向crontab加入一个新任务 sudo crontab -e #进入编 ...

  2. 【Tensorflow】Tensorflow r1.0, Ubuntu, gpu, conda安装说明

    Install Anaconda and python 1. cuda-8.0 download cuda_8.0.61_375.26_linux.run ./cuda_8.0.61_375.26_l ...

  3. 【Android开发坑系列】之事件分发机制

    总结一下: 事件序列的定义:从手触摸屏幕(含)到离开屏幕(含)期间所发生的一系列交互事件.主要由ACTION_DOWN.ACTION_MOVE.ACTOIN_UP.ACTION_CANCEL等组成,其 ...

  4. Cocos Lua的Touch 点击事件添加

    两种方式: -- 触摸开始 local function onTouchBegan(touch, event) return true end -- 触摸结束 local function onTou ...

  5. 物联网架构成长之路(25)-Docker构建项目用到的镜像1

    0. 前言 现在项目处于初级阶段,按照规划,先构建几个以后可能会用到的Image,并上传到阿里云的Docker仓库.以后博客中用到的Image,大部分都会用到这几个基础的Image,构建一个简单的物联 ...

  6. 深入分析 ThreadLocal

    ThreadLoacal是什么? ThreadLocal是啥?以前面试别人时就喜欢问这个,有些伙伴喜欢把它和线程同步机制混为一谈,事实上ThreadLocal与线程同步无关.ThreadLocal虽然 ...

  7. 安防工程商必须知道的PoE供电真相

    问题一:何为PoE技术? PoE (Power Over Ethernet)指的是在现有的以太网Cat.5布线基础架构不作任何改动的情况下,在为一些基于IP的终端(如IP电话机.无线局域网接入点AP. ...

  8. 【iCore4 双核心板_uC/OS-II】例程九:消息队列

    一.实验说明: 前面介绍通过信息传递可以进行任务间的交流,信息也可以直接发送给一个任务,在uC/OS-II中每一个任务在它们内部都有一个消息队列,也即任务消息队列,用户可以直接给一个任务发送消息,不需 ...

  9. perl控制流介绍(if条件,while,for循环,foreach)

    1. 语句块:{ }之间的部分即为BLOCK语句块. 2. 条件语句:if ( expression )  BLOCK; if ( expression )     BLOCK1else BLOCK2 ...

  10. R语言与机器学习学习笔记

    人工神经网络(ANN),简称神经网络,是一种模仿生物神经网络的结构和功能的数学模型或计算模型.神经网络由大量的人工神经元联结进行计算.大多数情况下人工神经网络能在外界信息的基础上改变内部结构,是一种自 ...