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 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
随机推荐
- ios http请求 配置
需要在xcode 中配置下才能请求
- 24_ajax请求_使用axios
前置说明: 1.React本身只关注页面,并不包含发送ajax请求的代码 2.前端应用需要通过ajax请求与后台进行交互(json数据) 3.React应用中需要集成第三方ajax库(或自己进行封装) ...
- pycharm 对数据库进行可视化操作
https://blog.csdn.net/qq_24189933/article/details/75666243
- 算法练习,链表二分最大n个
import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class Bin ...
- C++复习:纯虚函数和抽象类
纯虚函数和抽象类 1基本概念 2抽象类案例 3抽象类在多继承中的应用 C++中没有Java中的接口概念,抽象类可以模拟Java中的接口类.(接口和协议) 3.1有关多继承的说明 工程上的多继承 被 ...
- nginx+php 开启https
nginx 配置如下,配置好重启nginx,不是nginx -s reload,如果还不能访问肯定就是防火墙问题,关闭防火墙再试试. 我遇到的问题是:我服务器是ecs,域名解析到阿里云复杂均衡的,结果 ...
- 记录Git的安装过程
从https://git-scm.com/download/win,选择Windos版本下载. 选择打开的工具,用的Notepad. 下一步 下一步
- 福州大学软件工程W班-助教总结
背景 福州大学软件工程W班,总人数46人,讲师汪老师. 前期期望 希望自己能够在课程当中起到引导作用,发挥助教最大的用处. 实际执行情况 第一个问题是自动化测试工具,该工具主要是用来测试程序WordC ...
- 尚未解决的webpack问题
91% additional asset processing 打包过程中,在91%的时候会出现卡顿几秒 在js,css使用chunkhash替代hash 字体和图片:没有此chunkhash,只有h ...
- 网络层——IP报文头介绍
IP数据包也叫IP报文分组,传输在ISO网络7层结构中的网络层,它由IP报文头和IP报文用户数据组成,IP报文头的长度一般在20到60个字节之间,而一个IP分组的最大长度则不能超过65535个字节. ...