Codeforces 1131

比赛链接

hack一个暴力失败了两次最后还是没成功身败名裂= = CF跑的也太快了吧...

不过倒也涨了不少。

A.Sea Battle

//想麻烦了,但是无所谓...
#include <set>
#include <map>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <algorithm>
#define mp std::make_pair
#define pr std::pair<int,int>
#define pc putchar
#define gc() getchar()
typedef long long LL; inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now*f;
}
LL c(LL a,LL b)
{
return ((a+4+b)<<1)-4;
} int main()
{
LL w1=read(),h1=read(),w2=read(),h2=read();
LL ans=c(w1,h1)+c(w2,h2)-((std::min(w1,w2)+2)<<1);
printf("%d\n",ans); return 0;
}

B.Draw!

//有点不知道说什么...看代码吧...
#include <set>
#include <map>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <algorithm>
#define mp std::make_pair
#define pr std::pair<int,int>
#define pc putchar
#define gc() getchar()
typedef long long LL;
const int N=1e5+5; int A[N],B[N]; inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now*f;
} int main()
{
int n=read();
for(int i=1; i<=n; ++i) A[i]=read(),B[i]=read();
LL ans=0;
for(int i=1,las=0; i<=n; ++i)
{
int x=std::max(A[i-1],B[i-1]),y=std::min(A[i],B[i]);
x=std::max(x,las), las=y+1;
ans+=std::max(y-x+1,0);
}
printf("%I64d\n",ans); return 0;
}

C.Birthday

sort一下从中间往左右依次分配。没证,但感觉就是对的。

//31ms	0KB
#include <set>
#include <map>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <algorithm>
#define mp std::make_pair
#define pr std::pair<int,int>
#define pc putchar
#define gc() getchar()
typedef long long LL;
const int N=1e3+5; int A[N],B[N]; inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now*f;
} int main()
{
int n=read();
for(int i=1; i<=n; ++i) A[i]=read();
std::sort(A+1,A+1+n);
int mid=n+1>>1; B[mid]=A[1];
for(int i=3,t=mid-1; i<=n; i+=2) B[t--]=A[i];
for(int i=2,t=mid+1; i<=n; i+=2) B[t++]=A[i];
for(int i=1; i<=n; ++i) printf("%d ",B[i]); return 0;
}

D.Gourmet choice(拓扑排序)

容易想到拓扑一下分配数字。对于等号,就先把它们合并成一个连通块,再拓扑。

不合法情况就是同一连通块中出现了><

//61ms	43900KB
#include <set>
#include <map>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define mp std::make_pair
#define pr std::pair<int,int>
#define pc putchar
#define gc() getchar()
typedef long long LL;
const int N=1e6+5,M=1e3+5; int dgr[N],bel[N],fa[N],Ans[N];
char s[M][M];
struct Graph
{
int Enum,H[N],nxt[N],to[N];
inline void AE(int u,int v,int f)
{
dgr[v]+=f, to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
}
}G,T; inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now*f;
}
int Find(int x)
{
return x==fa[x]?x:fa[x]=Find(fa[x]);
}
bool Check(int n,int m,int cnt)
{
static int q[N];
int tot=n+m,h=0,t=0;
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
if(bel[i]==bel[j+n]&&s[i][j]!='=') return 0;
for(int i=1; i<=cnt; ++i) if(!dgr[i]) q[t++]=i, Ans[i]=1;
while(h<t)
{
int x=q[h++];
for(int i=T.H[x],v; i; i=T.nxt[i])
{
v=T.to[i], Ans[v]=std::max(Ans[v],Ans[x]+1);
if(!--dgr[v]) q[t++]=v;
}
}
if(t<cnt) return 0;
puts("Yes");
for(int i=1; i<=n; ++i) printf("%d ",Ans[bel[i]]);
puts("");
for(int i=n+1; i<=tot; ++i) printf("%d ",Ans[bel[i]]);
return t==cnt;
} int main()
{
int n=read(),m=read(),tot=n+m;
for(int i=1; i<=tot; ++i) fa[i]=i;
for(int i=1; i<=n; ++i)
{
scanf("%s",s[i]+1);
for(int j=1; j<=m; ++j)
if(s[i][j]=='>') G.AE(j+n,i,0);
else if(s[i][j]=='<') G.AE(i,j+n,0);
else fa[Find(i)]=Find(j+n);
}
int cnt=0;
for(int i=1; i<=tot; ++i) if(fa[i]==i) bel[i]=++cnt;
for(int i=1; i<=tot; ++i) if(fa[i]!=i) bel[i]=bel[Find(i)];
for(int x=1; x<=tot; ++x)
for(int i=G.H[x],v; i; i=G.nxt[i])
if(bel[x]!=bel[v=G.to[i]]) T.AE(bel[x],bel[v],1);
if(!Check(n,m,cnt)) puts("No"); return 0;
}

E.String Multiplication(思路)

从后往前对最后一个字符串\(p_n\)的前后缀是否相同讨论一下。具体看这里吧不想写了= =

可以像上面那样递归去做,也可以从\(p_1\)往后递推。因为用到的是某个字符的最长连续子串,所以令\(f[i][j]\)表示\(p_1\cdot p_2\cdot...\cdot p_i\)中\(j\)字符的最长连续长度,转移时判一下\(p_{i+1}\)是否都是由\(j\)字符构成的,是就用\(len\times(f[i][j]+1)+f[i][j]\)更新,否则用\(1+j字符的最长前后缀\)更新(\(p_{i-1}\)中含\(j\)字符才能转移)。

复杂度\(O(\sum|p_i|)\)(递归)或\(O(26\sum|p_i|)\)(递推)(然而前者常数比较大)。

//46ms	10100KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#define S 26
typedef long long LL;
const int N=1e5+5; int f[N][S],pre[S],suf[S];
char s[N]; void Solve(int *f)
{
scanf("%s",s+1);
int l=strlen(s+1);
for(int j=0; j<S; ++j)
{
int mx=0;
for(int i=1,cnt=0; i<=l; ++i)
if(s[i]==j+'a') mx=std::max(mx,++cnt);
else cnt=0;
f[j]=mx, pre[j]=suf[j]=0;
for(int i=1; i<=l; ++i)
if(s[i]==j+'a') ++pre[j];
else break;
for(int i=l; i; --i)
if(s[i]==j+'a') ++suf[j];
else break;
}
} int main()
{
int n; scanf("%d",&n);
Solve(f[1]);
for(int i=2; i<=n; ++i)
{
Solve(f[i]);
int l=strlen(s+1);
for(int j=0; j<S; ++j)
if(f[i-1][j])
if(pre[j]!=l) f[i][j]=std::max(f[i][j],pre[j]+suf[j]+1);
else f[i][j]=std::max(f[i][j],l*(f[i-1][j]+1)+f[i-1][j]);
}
int ans=0;
for(int i=0; i<S; ++i) ans=std::max(ans,f[n][i]);
printf("%d\n",ans); return 0;
}

F.Asya And Kittens(链表)

容易发现只要模拟一下按顺序合并连通块即可。可以用vector+启发式合并,也可以链表。用链表复杂度\(O(n\alpha(n))\)。

//78ms	1600KB
#include <set>
#include <map>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <algorithm>
#define mp std::make_pair
#define pr std::pair<int,int>
#define pc putchar
#define gc() getchar()
typedef long long LL;
const int N=150005; int fa[N],R[N],ed[N]; inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now*f;
}
int Find(int x)
{
return x==fa[x]?x:fa[x]=Find(fa[x]);
} int main()
{
int n=read();
for(int i=1; i<=n; ++i) fa[i]=ed[i]=i;
for(int i=1; i<n; ++i)
{
int x=read(),y=read();
int r1=Find(x),r2=Find(y);
fa[r2]=r1, R[ed[r1]]=r2, ed[r1]=ed[r2];
}
for(int i=1; i<=n; ++i)
if(fa[i]==i)
{
for(int x=i; x; x=R[x]) printf("%d ",x);
break;
} return 0;
}

G.Most Dangerous Shark

待填坑(怕是永远也填不上了)


Codeforces Round #541 (Div. 2) (A~F)的更多相关文章

  1. Codeforces Round #541 (Div. 2)

    Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  3. Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)

    D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: =  的情况我们用并查集把他们扔到一个集合,然后根据 > ...

  4. Codeforces 1131 F. Asya And Kittens-双向链表(模拟或者STL list)+并查集(或者STL list的splice()函数)-对不起,我太菜了。。。 (Codeforces Round #541 (Div. 2))

    F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #541 (Div. 2)题解

    不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...

  6. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  7. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  8. Codeforces Round #600 (Div. 2)E F

    题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...

  9. Codeforces Round #346 (Div. 2) E F

    因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...

随机推荐

  1. 第五周学习总结-HTML5

    2018年8月12日 暑假第五周,我把HTML剩余的一些标签和用法看完了并学了一些HTML5的标签及用法. HTML5比HTML多了一些元素,也删去了一些元素. HTML5新增元素 图形元素 < ...

  2. jQuery常见的几个文档处理方式

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. Mysql 查看连接数,状态 最大并发数

    show status like '%max_connections%'; ##mysql最大连接数set global max_connections=1000 ##重新设置show variabl ...

  4. 反序列化json的坑

    json格式没有错误,内容没有什么异常 反序列化一直显示第一行有异常符号, 在https://jsonlint.com/上面检测了一下,发现了这个 解决办法: UTF-8格式编码 改成 UTF-8无B ...

  5. 阻止Java反编译蛋疼方法

    public class landv { private static String companyName="landv测试"; public static void main( ...

  6. WCF三种通信方式

    一.概述 WCF在通信过程中有三种模式:请求与答复.单向.双工通信.以下我们一一介绍. 二.请求与答复模式 描述: 客户端发送请求,然后一直等待服务端的响应(异步调用除外),期间处于假死状态,直到服务 ...

  7. DevOps 在公司项目中的实践落地

    原文出处:https://www.cnblogs.com/beef/p/7743594.html ref: [DevOps]团队敏捷开发系列--开山篇 https://www.cnblogs.com/ ...

  8. adb devices unauthorized解决办法

    进行Android项目调试时,连接完设备,进行adb install ******.apk时,偶遇 adb devices unauthorized 这个小东西,解决办法:将手机设置->辅助功能 ...

  9. 【Android】Android 代码判断是否获取ROOT权限(二)

    [Android]Android 代码判断是否获取ROOT权限 方法比较简单,直接粘贴代码 /** * 判断当前手机是否有ROOT权限 * @return */ public boolean isRo ...

  10. 在启用了“编辑并继续”时,修改包含 lambda 表达式的“method”将会阻止调试会话继续进行

    将所有的引用的“复制到本地”属性都设置成false就可以了