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


A - Skyscrapers

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

AC代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e5+;
  4. int n,t[maxn];
  5. int l1,l2;
  6. int main()
  7. {
  8. cin>>n;
  9. for(int i=;i<=n;i++) scanf("%d",&t[i]);
  10.  
  11. l1=l2=;
  12. vector<int> v;
  13. for(int i=;i<=n;i++)
  14. {
  15. if(t[i]==) l1++, l2=;
  16. if(t[i]==) l2++, l1=;
  17.  
  18. if(i==n || t[i]!=t[i+])
  19. {
  20. if(l1>) v.push_back(l1);
  21. if(l2>) v.push_back(l2);
  22. }
  23. }
  24.  
  25. int ans=;
  26. for(int i=;i<v.size()-;i++)
  27. {
  28. if(min(v[i],v[i+])>ans) ans=min(v[i],v[i+]);
  29. }
  30. cout<<*ans<<endl;
  31. }

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代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=5e3+;
  4. int n;
  5. char c[maxn],a[maxn];
  6. int A,B,C,D;
  7. vector<int> t[][];
  8. int x,y,z;
  9. bool check()
  10. {
  11. for(x=;x<=B;x++)
  12. {
  13. for(z=;z<=D;z++)
  14. {
  15. y=x+z-D+z;
  16. if(y< || C-y<) continue;
  17. if(x+(C-y)+z>n/ || (B-x)+y+(D-z)>n/) continue;
  18. if(n/-(x+(C-y)+z) + n/-((B-x)+y+(D-z)) == A)
  19. {
  20. return ;
  21. }
  22. }
  23. }
  24. return ;
  25. }
  26. int main()
  27. {
  28. cin>>n;
  29. scanf("%s",c+);
  30. scanf("%s",a+);
  31.  
  32. A=B=C=D=;
  33. t[][].clear(), t[][].clear(), t[][].clear(), t[][].clear();
  34. for(int i=;i<=n;i++)
  35. {
  36. if(c[i]=='' && a[i]=='') A++, t[][].push_back(i);
  37. if(c[i]=='' && a[i]=='') B++, t[][].push_back(i);
  38. if(c[i]=='' && a[i]=='') C++, t[][].push_back(i);
  39. if(c[i]=='' && a[i]=='') D++, t[][].push_back(i);
  40. }
  41.  
  42. if(check()==) cout<<"-1\n";
  43. else
  44. {
  45. // cout<<(n/2-(x+(C-y)+z))<<endl;
  46. // cout<<x<<endl;
  47. // cout<<C-y<<endl;
  48. // cout<<z<<endl;
  49.  
  50. for(int i=;i<n/-(x+(C-y)+z);i++) printf("%d ",t[][][i]);
  51. for(int i=;i<x;i++) printf("%d ",t[][][i]);
  52. for(int i=;i<C-y;i++) printf("%d ",t[][][i]);
  53. for(int i=;i<z;i++) printf("%d ",t[][][i]);
  54. }
  55. }

C - Skyscrapers - [离散化]

题意:

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

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

题解:

离散化裸题。

AC代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,m;
  4. int h[][];
  5. vector<int> r[],c[];
  6. int main()
  7. {
  8. ios::sync_with_stdio();
  9. cin.tie(), cout.tie();
  10.  
  11. cin>>n>>m;
  12. for(int i=;i<=n;i++)
  13. for(int j=;j<=m;j++)
  14. cin>>h[i][j];
  15.  
  16. for(int i=;i<=n;i++)
  17. {
  18. for(int j=;j<=m;j++) r[i].push_back(h[i][j]);
  19. sort(r[i].begin(),r[i].end());
  20. r[i].erase(unique(r[i].begin(),r[i].end()),r[i].end());
  21. }
  22. for(int j=;j<=m;j++)
  23. {
  24. for(int i=;i<=n;i++) c[j].push_back(h[i][j]);
  25. sort(c[j].begin(),c[j].end());
  26. c[j].erase(unique(c[j].begin(),c[j].end()),c[j].end());
  27. }
  28.  
  29. for(int i=;i<=n;i++)
  30. {
  31. for(int j=;j<=m;j++)
  32. {
  33. int tp1=lower_bound(r[i].begin(),r[i].end(),h[i][j])-r[i].begin();
  34. int tp2=lower_bound(c[j].begin(),c[j].end(),h[i][j])-c[j].begin();
  35. int tp3=r[i].end()-lower_bound(r[i].begin(),r[i].end(),h[i][j]);
  36. int tp4=c[j].end()-lower_bound(c[j].begin(),c[j].end(),h[i][j]);
  37. printf("%d ",max(tp1,tp2)+max(tp3,tp4));
  38. }
  39. printf("\n");
  40. }
  41. }

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. CentOS 7 安装 Oracle 11.2.0.4

    一.安装环境 CentOS Linux release 7.2.1511 (Core) Oracle Database 11g Release 2 (11.2.0.4) 二.安装前准备 2.1 修改主 ...

  2. springcloud如何实现服务的平滑发布

    在之前的文章中我们提到服务的优雅下线,见: SpringCloud服务如何在Eureka安全优雅的下线 但这个对于ribbon调用其实是不平滑的,shutdown请求到后服务就马上关闭了,服务消费此时 ...

  3. 【centos6.6环境搭建】Github unable to access SSL connect error出错处理

    问题 克隆github项目出现SSL connect error git clone https://github.com/creationix/nvm Cloning into 'nvm'... f ...

  4. 在Centos7下安装nghttp2

    如果是Ubuntu18.04, 系统本身已经带了nghttp2了, 直接apt安装就可以. 下载源代码 https://github.com/nghttp2/nghttp2 如果是在Ubuntu下编译 ...

  5. ROM后缀含义

    ROM files, unless altered by the uploader, always have special suffixes to quickly denote what the s ...

  6. mac下安装xampp、及其之上的组件安装

    由于mac下开发需要用到php7,这里是用的xampp集成开发版本.但是mac下安装xampp失败,失败信息如下: Error starting "XAMPP" stack: fa ...

  7. 使用viewport中的vm来适配移动端页面

    前言 作为一个小前端,经常要和H5打交道,这就面临着不同终端的适配问题. Flexible方案通过Hack手段来根据设备的dpr值相应改变<meta>标签中viewport的值,给我更贴切 ...

  8. Linux系统查毒软件ClamAV (online)

    ClamAV是一个可用于Linux平台上的开源杀毒引擎,可检测木马.病毒.恶意软件和其他恶意的威胁. 官网:http://www.clamav.net/ 一.CentOS环境安装 # yum inst ...

  9. CobaltStrike3.12/13 破解

    更新3.13破解版 链接: https://pan.baidu.com/s/14e0tpVPzUhiAhYU2_jvBag 提取码: d9uf MacOS客户端: 链接: https://pan.ba ...

  10. docker被屏蔽后下载方法

    docker镜像默认的官网上传平台:https://hub.docker.com/,k8s运行时需要从google下载镜像(k8s.gcr.io),但该网被屏蔽了,怎样下载到所需镜像呢? 1. 可在知 ...