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 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
随机推荐
- Android SDK版本号与API Level 的对应关系-转
Android SDK版本号 与 API Level 对应关系 http://developer.android.com/guide/appendix/api-levels.html Android ...
- Java基础—常用类之String类
一.String类是什么 public final class String implements java.io.Serializable, Comparable<String>, Ch ...
- Metasploit简单应用
什么是Metasploit Metasploit是一款开源的安全漏洞检测工具. 它可以帮助用户识别安全问题,验证漏洞的缓解措施,并对某些软件进行安全性评估,提供真正的安全风险情报.当我们第一次接触Me ...
- 12、JAVA内存模型与线程
一.JMM 有序性,可见性,原子性 synchorize :3个性都有: volatile:保证可见性+禁止指令重排: 二.线程的五种状态 面向过程与面向对象的差别 面向过程:站在计算机的角度分析和解 ...
- HDU-6356 Glad You Came (线段树)
题目链接:Glad You Came 题意:数组有n个数初始为0,m个询问,每个询问给出L R V(按照给定函数生成),将数组的下标L到R的数与V取较大值,最后输出给定的公式结果. 题意:哇~打比赛的 ...
- pycharm如何全局进行查找一个关键词
PyCharm的Find in Path功能提供了全局查找功能,快捷键为Ctrl + Shift + F.Find则是在当前文件查找,快捷键为Ctrl + F.这两个个功能非常实用. Find in ...
- 在git与tortoisegit中使用openSSH与PuTTY
问题 在使用Git与tortoisegit的时候,指定远程版本库的地址有2种方式: 使用https方式的git地址非常直接(https://xxx.oschina.net/xxx.git),基本上什么 ...
- SQL Server Integration Services的10大最佳实践
原文出处:https://blogs.msdn.microsoft.com/sqlcat/2013/09/16/top-10-sql-server-integration-services-best- ...
- imagick用法!
https://coderwall.com/p/9hj97w sudo apt-get install imagemagick sudo apt-get install php5-imagick su ...
- Alpha阶段个人贡献分
根据任务完成情况与之前的评分标准,我们给组员分数如下: 团队成员 最终得分 程刚 49 李睿琦 50 刘丽萍 52 刘宇帆 53 王力民 54 杨昊岚 41 左少辉 51 转会人员: 杨昊岚转到Our ...