Codeforces Round #541
因为这次难得不在十点半(或是更晚),大家都在打,然后我又双叒叕垫底了=。=
自己对时间的分配,做题的方法和心态还是太蒻了,写的时候经常写一半推倒重来。还有也许不是自己写不出来,而是在开始写之前就觉得自己写不出来
多打CF
A.Sea Battle
讨论.jpg
也有式子的解法,我没想
B.Draw
讨论失败.jpg
(写题顺序:ADFC,没有B)
讨论个**,转化成线段求交,答案就是$\sum max(0,min(x,y)-max(lstx,lsty)+(lstx!=lsty))$,记得加上一开始的1
C.Birthday
赛场降智->枚举两边$n^2$+排序后中间轮着放检查$n$->$n^3$睿智算法
正确答案->不知为啥还要枚举,排序以后直接轮着放->$n\log n$
D.Gourmet choice
并查集+拓扑排序
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,M=;
int num[N],aset[N],que[N],bel[N];
int p[N],noww[M],goal[M],deg[N];
int n,m,f,b,t1,t2,cnt,tot,ff;
char rd[][];
int Finda(int x)
{
return x==aset[x]?x:aset[x]=Finda(aset[x]);
}
void Link(int f,int t)
{
noww[++cnt]=p[f],deg[t]++;
goal[cnt]=t,p[f]=cnt;
}
int main ()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n+m;i++) aset[i]=i;
for(int i=;i<=n;i++)
{
scanf("%s",rd[i]+);
for(int j=;j<=m;j++)
if(rd[i][j]=='=')
aset[Finda(i)]=Finda(j+n);
}
for(int i=;i<=n+m;i++) bel[i]=Finda(i);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
if(rd[i][j]=='<') Link(bel[i],bel[j+n]);
if(rd[i][j]=='>') Link(bel[j+n],bel[i]);
}
for(int i=;i<=n+m;i++)
if(!deg[i]) que[++b]=i,num[i]=;
while(f<=b)
{
int tn=que[f++];
for(int i=p[tn];i;i=noww[i])
if(!(--deg[goal[i]]))
que[++b]=goal[i],num[goal[i]]=num[tn]+;
}
for(int i=;i<=n+m;i++) if(deg[i]) printf("No"),exit(); puts("Yes");
for(int i=;i<=n;i++) printf("%d ",num[bel[i]]); puts("");
for(int i=n+;i<=n+m;i++) printf("%d ",num[bel[i]]);
return ;
}
E.String Multiplication
请讨论.jpg
答案只和最大子段,前缀连续和后缀连续有关,枚举哪个字符作为答案之后再统计就比较简单了
但是仍然有很多细节=。=
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=;
string str[N]; long long ans;
int main()
{
int n; cin>>n;
for(int i=;i<=n;i++)
cin>>str[i];
for(int i='a';i<='z';i++)
{
long long maxi=;
for(int j=;j<=n;j++)
{
int len=str[j].size();
long long lst=,tmp=,pre=,suf=;
for(int k=;k<len;k++)
(str[j][k]==i)?lst=max(lst,++tmp):tmp=;
if(lst||maxi)
{
for(int k=;k<len;k++)
if(str[j][k]==i) pre++;
else break;
for(int k=len-;~k;k--)
if(str[j][k]==i) suf++;
else break;
if(lst==len) maxi=(maxi+)*lst+maxi;
else maxi=maxi?max(lst,pre+suf+):lst;
}
}
ans=max(ans,maxi);
}
printf("%lld",ans);
return ;
}
F.Asya And Kittens
并查集维护小猫之间的连通性,同时维护每只小猫的下一只小猫和当前小猫链里最后一只小猫是谁。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,st,t1,t2,cnt;
int aset[N],nxt[N],endp[N];
int Finda(int x)
{
return x==aset[x]?x:aset[x]=Finda(aset[x]);
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) aset[i]=endp[i]=nxt[i]=i;
for(int i=;i<n;i++)
{
scanf("%d%d",&t1,&t2);
int t3=Finda(t1),t4=Finda(t2);
aset[t3]=t4,nxt[endp[t4]]=t3,endp[t4]=endp[t3];
}
for(int i=;i<=n;i++)
if(Finda(i)==i) {st=i; break;}
while(nxt[st]!=st)
printf("%d ",st),st=nxt[st];
printf("%d",st);
return ;
}
G.Most Dangerous Shark
单调栈优化DP,代码咕咕了
Codeforces Round #541的更多相关文章
- Codeforces Round #541 (Div. 2)
Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...
- Codeforces Round #541 (Div. 2)题解
不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...
- Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)
D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: = 的情况我们用并查集把他们扔到一个集合,然后根据 > ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序
https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...
- Codeforces Round #541 (Div. 2) C.Birthday
链接:https://codeforces.com/contest/1131/problem/C 题意: 求给的n个数,相邻差值最小的排列方式.1-n相邻. 思路: sort后隔一个取一个,取到底后再 ...
- Codeforces Round #541 (Div. 2) B.Draw!
链接:https://codeforces.com/contest/1131/problem/B 题意: 给n次足球比分,求存在平局的机会. 思路: 结构体存储,unique后,判断是否有分数交叉. ...
- Codeforces Round #541 (Div. 2) A.Sea Battle
链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
随机推荐
- 20155333 《网络对抗》 Exp6 信息搜集与漏洞扫描
20155333 <网络对抗> Exp6 信息搜集与漏洞扫描 基础问题 哪些组织负责DNS,IP的管理? 全球根服务器均由美国政府授权的ICANN统一管理,负责全球的域名根服务器.DNS和 ...
- Java通过pinyin4j实现汉字转拼音
碰到个需求,需要按用户名字的首字母来排序.这就需要获取汉字对应的拼音了,突然就想起了pinyin4j这个jar包,于是就开始写了个汉字转拼音的工具类.在此记录一下,方便后续查阅 一.Pom依赖 ...
- Mybatis初步详细配置
1.Mybatis所需包 下载地址:https://github.com/mybatis/mybatis-3/releases,其中log4j是日志包,mysql是数据库所需包,需自行下载 2.项目结 ...
- Activity猫的一生-故事解说Activity生命周期
大家好,关于Android中Activity的生命周期,网上大多数文章基本都是直接贴图.翻译API,比较笼统含糊不清. 我就用故事来说一说: 有个人叫User,TA养了几只猫,有只猫叫Activity ...
- EntityFramework Core 2.x (ef core) 在迁移中自动生成数据库表和列说明
在项目开发中有没有用过拼音首字母做列名或者接手这样的项目? 看见xmspsqb(项目审批申请表)这种表名时是否有一种无法抑制的想肛了取名的老兄的冲动? 更坑爹的是这种数据库没有文档(或者文档老旧不堪早 ...
- 如何基于 K8S 多租能力构建 Serverless Container
当前 Kubernetes 已经成为名副其实的企业级容器编排规范,很多云平台都开始提供兼容 Kubernetes 接口的容器服务.而在多用户支持方面,多数平台选择直接提供专属虚机集群,用户需要花费大量 ...
- muduo网络库学习笔记(四) 通过eventfd实现的事件通知机制
目录 muduo网络库学习笔记(四) 通过eventfd实现的事件通知机制 eventfd的使用 eventfd系统函数 使用示例 EventLoop对eventfd的封装 工作时序 runInLoo ...
- [T-ARA][O My God]
歌词来源:http://music.163.com/#/song?id=22704432 눈을 뜨면 생각이나고 길을 걷다 생각이나고 [nu-neul ddeu-myeon saeng-ga-gi ...
- 转-PHP 设计模式 之策略模式 应用场景 Strategy Pattern
一.前言 关于设计模式的文章,园子里实在是太多太多,而且讲解的也非常精彩,那为什么我还要在这里记录下这篇文章?本文以实际项目应用“自己动手写工具--XSmartNote”为切入点,来讲述策略模式的应用 ...
- Scrum Meeting NO.2
Scrum Meeting No.2 1.会议内容 今天,我们对已经确定的任务进行了分配,并针对界面设计方面的细节进行讨论. 由于这周其它课程任务繁重(编译+数据库).前端的任务主要分配给编程能力较好 ...