Codeforces Round #541 (Div. 2)
Codeforces Round #541 (Div. 2)
http://codeforces.com/contest/1131
A
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
ll w1,h1,w2,h2;
cin>>w1>>h1>>w2>>h2;
ll tmp1=(w2+)*(h2+);//上面的
ll tmp2=(w1+)*(h1+);
ll tmp3=w1*h1+w2*h2;
ll ans=tmp1+tmp2-tmp3-*(w2+);
cout<<ans<<endl;
}
B
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
ll a,b,x,y;
x=,y=;
ll ans=;
for(int i=;i<=n;i++){
cin>>a>>b;
ans+=max(0LL,min(a,b)-max(x,y)+(x!=y));
x=a,y=b;
}
cout<<ans<<endl;
}
C
sort排序,然后从小到大依次左右各添一个向中间添加。。。在比赛的时候第一感觉这就是正解,但是不会证明为什么。。。
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int a[];
int ans[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
sort(a+,a+n+);
int L=,R=n;
int i=;
while(L<=R){
if(i%)
ans[L++]=a[i];
else
ans[R--]=a[i];
i++;
}
for(int i=;i<=n;i++) cout<<ans[i]<<" ";
}
D
用并查集把相同的点连在一起,然后剩下的点用拓扑排序即可
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 2005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int n,m;
char str[][]; int fa[maxn];
int d[maxn];
int vis[maxn];
int ans[maxn];
vector<int>ve[maxn]; int Find(int x){
int r=x,y;
while(x!=fa[x]){
x=fa[x];
}
while(r!=x){
y=fa[r];
fa[r]=x;
r=y;
}
return x;
} void join(int x,int y){
int xx=Find(x);
int yy=Find(y);
fa[xx]=yy;
} void add(int x,int y){
int xx=Find(x);
int yy=Find(y);
if(xx!=yy){
d[xx]++;
ve[yy].pb(xx);
}
else{
cout<<"NO"<<endl;
exit();
}
} void topsort(){
queue<pair<int,int> >Q;
rep(i,,n+m+){
int xx=Find(i);
if(!d[xx]&&!vis[xx]){
vis[xx]=;
Q.push(make_pair(xx,));
}
}
pair<int,int>pp;
while(!Q.empty()){
pp=Q.front();
Q.pop();
int pos=pp.first;
int v=pp.second;
ans[pos]=v;
rep(i,,ve[pos].size()){
int w=ve[pos][i];
d[w]--;
if(!d[w]){
Q.push(make_pair(w,v+));
}
}
}
rep(i,,n+m+){
if(d[i]){
cout<<"NO"<<endl;
exit();
}
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
rep(i,,n+m+) fa[i]=i;
rep(i,,n+) cin>>(str[i]+);
rep(i,,n+){
rep(j,,m+){
if(str[i][j]=='='){
join(Find(i),Find(j+n));
}
}
}
rep(i,,n+){
rep(j,,m+){
if(str[i][j]=='>'){
add(i,n+j);
}
else if(str[i][j]=='<'){
add(n+j,i);
}
}
}
topsort();
cout<<"YES"<<endl;
rep(i,,n+) cout<<ans[Find(i)]<<" ";
cout<<endl;
rep(i,,m+) cout<<ans[Find(i+n)]<<" ";
}
E
类似模拟的方法
找出字符串的连续前缀,连续后缀和中间最长连续子串
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int ans=;
string s[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>s[i];
}
for(int c=;c<;c++){
int l=,r=,all=;
for(int i=n-;i>=;i--){
int cnt=,pf=,sf=,tt=;
while(pf<s[i].length()&&s[i][pf]=='a'+c) ++pf;
while(sf<s[i].length()&&s[i][s[i].length()--sf]=='a'+c) ++sf;
for(int j=;j<s[i].length();j++){
if(s[i][j]=='a'+c){
cnt=max(cnt,++tt);
}
else{
tt=;
}
}
if(all){
ans=max(ans,(cnt+)*(l+)-);
l=(pf+)*(l+)-;
r=(sf+)*(r+)-;
if(pf!=s[i].length()){
all=;
}
}
else{
if(cnt){
ans=max(ans,l+r+);
}
}
}
}
cout<<ans<<endl;
}
F
比赛的时候犯傻了,一直在想建图,然后找度为1的点,然后深搜的错误性。。没想出来。后来才知道了错误性
正解应该是:并查集,合并就完事了
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; vector<int>ve[]; int fa[]; int Find(int x){
int r=x,y;
while(x!=fa[x]){
x=fa[x];
}
while(r!=x){
y=fa[r];
fa[r]=x;
r=y;
}
return x;
} void join(int x,int y){
int xx=Find(x);
int yy=Find(y);
if(ve[xx].size()>ve[yy].size()){
swap(xx,yy);
}
rep(i,,ve[xx].size()){
ve[yy].pb(ve[xx][i]);
fa[ve[xx][i]]=yy;
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin>>n;
rep(i,,n+) fa[i]=i,ve[i].pb(i);
int u,v;
rep(i,,n){
cin>>u>>v;
join(u,v);
}
int pos=Find();
rep(i,,ve[pos].size()){
cout<<ve[pos][i]<<" ";
} }
Codeforces Round #541 (Div. 2)的更多相关文章
- 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 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
随机推荐
- JConsole 配置
Tomcat 1:修改catalina.sh文件如下 JAVA_OPTS="-Djava.rmi.server.hostname=XXX.XXX.XXX.XXX -Dcom.sun.mana ...
- csv操作
需要引入javacsv.jar 以下为一个完整的Utils的写法,具体输出和输入需要自己修改参数. import java.io.File; import java.io.FileNotFoundEx ...
- ELK实时日志分析平台环境部署--完整记录(转)
在日常运维工作中,对于系统和业务日志的处理尤为重要.今天,在这里分享一下自己部署的ELK(+Redis)-开源实时日志分析平台的记录过程(仅依据本人的实际操作为例说明,如有误述,敬请指出)~ ==== ...
- C#实现联合体
[StructLayout(LayoutKind.Explicit, Size = )] public struct TypeTransform { [FieldOffset()] public fl ...
- 将应用部署到Tomcat根目录下
方法一:(最简单直接的方法) 删除原 webapps/ROOT 目录下的所有文件,将应用下的所有文件和文件夹复制到ROOT文件夹下. 方法二: 删除原webapps/ROOT 目录下的所有文件,修改文 ...
- Unable to connect to zookeeper server within timeout: 5000
错误 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error crea ...
- Haskell语言学习笔记(78)fix
fix 函数 fix 是一个在 Data.Function 模块中定义的函数,它是对于递归的封装,可以用于定义不动点函数. fix :: (a -> a) -> a fix f = let ...
- 直接在浏览器运行jsx及高版本的js代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- ArcGIS(ESRI)的发展历史和版本历史(简介)
作者:fenghuayoushi 来源:CSDN 原文:https://blog.csdn.net/fenghuayoushi/article/details/6677360 ESRI公司介绍 ...
- MPI Maelstrom-单源最短路-Djsktra
BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distribute ...