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)的更多相关文章

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

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

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

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

  3. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

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

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

  5. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

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

    https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...

  7. Codeforces Round #541 (Div. 2) C.Birthday

    链接:https://codeforces.com/contest/1131/problem/C 题意: 求给的n个数,相邻差值最小的排列方式.1-n相邻. 思路: sort后隔一个取一个,取到底后再 ...

  8. Codeforces Round #541 (Div. 2) B.Draw!

    链接:https://codeforces.com/contest/1131/problem/B 题意: 给n次足球比分,求存在平局的机会. 思路: 结构体存储,unique后,判断是否有分数交叉. ...

  9. Codeforces Round #541 (Div. 2) A.Sea Battle

    链接:https://codeforces.com/contest/1131/problem/A 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...

随机推荐

  1. Rabbitmq(3) work queues

    轮询分发:每个消费者处理的消息是一样的 公平分发:能者多劳 *****公平分发 生产者 package com.aynu.bootamqp.service; import com.aynu.boota ...

  2. mysql 累加求和

    ; SELECT temp.*,(@csum := total + @csum) as csums from ( ) as total,month(openedDate) as date from z ...

  3. sql 日期格式

    select CONVERT(varchar(10), getDate(),121) --不要时间2002-01-01 select CONVERT(varchar(10), getDate(),12 ...

  4. CentOS 7.0安装配置Vsftp服务器步骤详解

    安装Vsftp讲过最多的就是在centos6.x版本中了,这里小编看到有朋友写了一篇非常不错的CentOS 7.0安装配置Vsftp服务器教程,下面整理分享给各位. 一.配置防火墙,开启FTP服务器需 ...

  5. 人脸识别68个点<转>

    [Opencv] 于仕琪 人脸68个特征点分布情况 // 鼻尖 30 // 鼻根 27 // 下巴 8 // 左眼外角 36 // 左眼内角 39 // 右眼外角 45 // 右眼内角 42 // 嘴 ...

  6. leetcode解题报告 32. Longest Valid Parentheses 动态规划DP解

    dp[i]表示以s[i]结尾的完全匹配的最大字符串的长度. dp[] = ; ; 开始递推 s[i] = ')' 的情况 先想到了两种情况: 1.s[i-1] = '(' 相邻匹配 这种情况下,dp ...

  7. iOS 证书, provision profile作用

    证书(certificate): 给app签名用的,针对开发者,app可以装在真机上的前提条件之一是被签名 Provision profile: 在app包中,用来校验app是否可以被装在真机上,一个 ...

  8. vue.js 初级之一

    vue.js 是一个构建数据驱动的 web 界面 渐进式驱动框架. 引用的话,直接使用script标签引入就可以了: <script src="./lib/vue.js"&g ...

  9. 如何查看一个class文件是否正确

    今天碰到了个问题,左思右想就是找不出问题,试验多个路径来解决问题,错误依旧. 然后我拿到了现场的包,一个很大的问题让我忽略了,这个class文件用反编译程序打不开(jd-gui.exe),非常神奇,但 ...

  10. harbor仓库镜像的删除

    harbor仓库镜像的删除 刚开始自己摸索了下,直接webui界面删除后,发现仓库空间未释放 上传之前仓库空间占用为 上传之后仓库空间占用为 在webui界面上删除镜像后 查看大小 依旧为286m,到 ...