概述

切了 ABCE,Room83 第一

还行吧


A - Happy Birthday, Polycarp!

题解

显然这样的数不会很多。

于是可以通过构造法,直接求出 \([1,10^9]\) 内所有符合要求的数。

\(\mathrm{Code}\)

#include<bits/stdc++.h>
using namespace std; int a[]={1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,111,222,333,444,555,666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,11111,22222,33333,44444,55555,66666,77777,88888,99999,111111,222222,333333,444444,555555,666666,777777,888888,999999,1111111,2222222,3333333,4444444,5555555,6666666,7777777,8888888,9999999,11111111,22222222,33333333,44444444,55555555,66666666,77777777,88888888,99999999,111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999,1000000001}; int T,n; int main(){
cin>>T;
while(T--){
cin>>n;int ans=0;
for(int i=1;a[i]<=n;i++) ++ans;
cout<<ans+1<<endl;
}
return 0;
}

B - Make Them Odd

题解

显然每次从最大的数进行处理最划算。

于是用个优先队列存储所有的数,用 map 记录这个数是否还要付出代价即可。

\(\mathrm{Code}\)

#include<bits/stdc++.h>
using namespace std; const int maxn=2000007; int T,n;
int a[maxn];
int b[maxn],t[maxn];
int m;
map<int,bool>mp; #define pii(x,y) make_pair(x,y)
priority_queue < int>q;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);mp.clear();
int ans=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
q.push(a[i]);
}
while(q.size()){
int x=q.top();//x=-x;
q.pop();
if(x&1) continue;
if(mp[x]) continue;
++ans;mp[x]=1;
q.push(x/2);
}
printf("%d\n",ans);
}
}

C - As Simple as One and Two

题解

这种题目 WA 了一次 pretest ,说明我水平低下。

twoone 放在一起是非常美妙的字符串。

如果有子串 twone ,显然删去中间的 o 最优。

再处理 twoone ,为了不造成新的这样的串,删掉中间的 wn

\(\mathrm{Code}\)

#include<bits/stdc++.h>
using namespace std; const int maxn=150007; int T,val[maxn];
char s[maxn]; int ans[maxn],cnt; int main(){
scanf("%d",&T);
while(T--){
scanf("%s",s+1);
int len=strlen(s+1);cnt=0;
memset(val,0,sizeof(val));
for(int i=1;i+4<=len;i++){
if(s[i]=='t'&&s[i+1]=='w'&&s[i+2]=='o'&&s[i+3]=='n'&&s[i+4]=='e'){
ans[++cnt]=i+2;
s[i+2]=' ';
}
}
for(int i=1;i+2<=len;i++){
if(s[i]=='o'&&s[i+1]=='n'&&s[i+2]=='e'){
ans[++cnt]=i+1;s[i+1]=' ';
}
if(s[i]=='t'&&s[i+1]=='w'&&s[i+2]=='o'){
ans[++cnt]=i+1;s[i+1]=' ';
}
}
printf("%d\n",cnt);
for(int i=1;i<=cnt;i++){
printf("%d ",ans[i]);
}
puts("");
}
}

E - Two Fairs

题解

这种傻逼题花了一个小时还 WA 了一次 pretest,说明我水平低下。

扫一遍,并查集一下就行了。

神仙 zzk 有两次 bfs 的做法?

\(\mathrm{Code}\)

#include<bits/stdc++.h>
using namespace std; const int maxn=200007;
const int maxm=1000007; int T;
int n,m,a,b; #define pii(x,y) make_pair(x,y) vector <pair<int,int> >e; int cnt; int f[maxn]; set<int>A,B; void clear(void){
e.clear();
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++) f[i]=i;
A.clear();B.clear();
} int find(int x){
return f[x]==x?x:f[x]=find(f[x]);
} void merge(int x,int y){
int xx=find(x),yy=find(y);
if(xx!=yy) f[xx]=yy;
} void Init(void){
// for(int i=1;i<=n;i++){
// cout<<f[i]<<" ";
// }
for(int i=1,x,y;i<=m;i++){
scanf("%d%d",&x,&y);
if(a!=x&&a!=y&&b!=x&&b!=y) merge(x,y);
else e.push_back(pii(x,y));
}
// for(int i=1;i<=n;i++){
// cout<<f[i]<<" ";
// }
} void Work(void){
for(auto it:e){
int x=it.first,y=it.second;
if(y<x) swap(x,y);
if(a==x) A.insert(find(y));
if(a==y) A.insert(find(x));
if(b==x) B.insert(find(y));
if(b==y) B.insert(find(x));
}
int aa=0,bb=0;
for(int i=1;i<=n;i++){
// if(i==a||i==b) continue;
if(i!=a&&i!=b&&A.count(find(i))&&B.count(find(i))==0) ++aa;
if(i!=a&&i!=b&&B.count(find(i))&&A.count(find(i))==0) ++bb;
}
for(auto it:e) merge(it.first,it.second);
if(find(a)==find(b)) printf("%d\n",aa*bb);
else puts("0");
} int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d",&n,&m,&a,&b);
clear();
Init();
Work();
}
}

20191214 Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)的更多相关文章

  1. 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...

  2. Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    链接 签到题,求出位数,然后9*(位数-1)+ 从位数相同的全一开始加看能加几次的个数 #include<bits/stdc++.h> using namespace std; int m ...

  3. Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) 题解

    Happy Birthday, Polycarp! Make Them Odd As Simple as One and Two Let's Play the Words? Two Fairs Bea ...

  4. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

    A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...

  5. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

    A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最 ...

  6. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products

    链接: https://codeforces.com/contest/1247/problem/D 题意: You are given n positive integers a1,-,an, and ...

  7. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary

    链接: https://codeforces.com/contest/1247/problem/C 题意: Vasya will fancy any number as long as it is a ...

  8. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)

    链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard ver ...

  9. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) A. Forgetting Things

    链接: https://codeforces.com/contest/1247/problem/A 题意: Kolya is very absent-minded. Today his math te ...

随机推荐

  1. Win32_DiskDrive 硬盘 参数说明

    Availability  --设备的状态. BytesPerSector  --在每个扇区的物理磁盘驱动器的字节数. Capabilities  --媒体访问设备的能力阵列. CapabilityD ...

  2. BBS项目知识点汇总

    目录 bbs项目知识点汇总 一. JavaScript 1 替换头像 2 form表单拿数据 3 form组件error信息渲染 4 添加html代码 5 聚焦操作 二 . html在线编辑器 三 . ...

  3. SpringBoot电商项目实战 — 前后端分离后的优雅部署及Nginx部署实现

    在如今的SpringBoot微服务项目中,前后端分离已成为业界标准使用方式,通过使用nginx等代理方式有效的进行解耦,并且前后端分离会为以后的大型分布式架构.弹性计算架构.微服务架构.多端化服务(多 ...

  4. LeetCode刷题总结-树篇(下)

    本文讲解有关树的习题中子树问题和新概念定义问题,也是有关树习题的最后一篇总结.前两篇请参考: LeetCode刷题总结-树篇(上) LeetCode刷题总结-树篇(中) 本文共收录9道题,7道中等题, ...

  5. Nginx代理缓存功能

    Nginx代理缓存功能      Nginx缓存主要是用于减轻后端服务器的负载,提高网站并发量,提升用户体验度. 注意:Nginx反向代理的缓存功能是由ngx_http_proxy_module提供, ...

  6. 办公达人私藏的EXCEL辅助工具,一人抵十人,高效办公就靠它了!

    有很多小伙伴在日常工作中都离不开EXCEL的使用,但EXCEL实在是有太多困难.又复杂的操作,时间紧任务重这一天又废柴了,哎! 别担心,今天将为您分享个逆天强大的EXCEL辅助工具,帮大家快速搞定—— ...

  7. Springboot整合redis步骤

    一.加入依赖 <dependency> <groupId>com.github.spt-oss</groupId> <artifactId>spring ...

  8. gitlab如何从Github导入项目

    本文简单演示如何Github上导入项目到私人搭建的Gitlab中,搭建过程参考:CentOS7 搭建gitlab服务器. Gitlab版本是gitlab-ce-12.0.2,界面可能稍有差异,但应该影 ...

  9. C语言笔记 06_作用域&数组

    作用域 任何一种编程中,作用域是程序中定义的变量所存在的区域,超过该区域变量就不能被访问.C 语言中有三个地方可以声明变量: 在函数或块内部的局部变量 在所有函数外部的全局变量 在形式参数的函数参数定 ...

  10. 使用vue脚手架快速创建vue项目(入门)

    1.安装环境 为了方便,以下操作大多数中命令行中运行,window可以用cmd,powershell,gitbash等. 安装node.js 打开它的官网,或者中文网站,然后直接下载就可以了,然后跟安 ...