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 题意: 给两个矩形,一个再上一个在下,求两个矩形合并的周围一圈的面积. 思路: 因为存在下面矩形宽度大 ...
随机推荐
- 利用STM32CubeMX之SPI
现在我们继续使用STM32CubeMX来生成SPI工程.我们的硬件平台还是我们熟悉的STM32F103C8开发板. 设置时钟树中的配置 现在打开SPI的设置 如果想修改管脚的名字可以红色框中进行修改, ...
- vue的初识与简单使用---前后端分离通过接口调取数据
vue的安装 #### .环境搭建 ''' - 安装node ``` 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ ``` - 安装cnpm ``` npm inst ...
- 健康检测文件httpchk.jsp
静态显示: <html><body><center> Now time is: <%=new java.util.Date()%> </cente ...
- English Conversation – NUMBERS
English Conversation – NUMBERS Share Tweet Share Tagged With: Numbers Study the pronunciation of num ...
- VMware安装RHEL5.5后修改分辨率设置
1.进入桌面后,点击System -> Administration -> Display,选择Hardware,点击Monitor Type后面的Configure(默认是autocon ...
- 360sdk网游支付服务
网游支付服务 目录 1.流程介绍2.接口介绍2.1支付接口[客户端调用](必接)2.2支付结果通知接口–应用服务器提供接口, 由360服务器回调(必接)2.3订单核实接口– 服务器端接口, 应用服 ...
- List,Set,Map集合的遍历方法
List的三种实现:ArrayList(数组) LinkedList(链表) Vector(线程安全) List集合遍历方法: List<String> list = new Arra ...
- pycahrm 激活
Linux在/etc/hosts中添加 0.0.0.0 account.jetbrains.com就好,直接添加:0.0.0.0 account.jetbrains.comwindows的话没记错应该 ...
- Oracle查看SQL执行计划的方式
Oracle查看SQL执行计划的方式 获取Oracle sql执行计划并查看执行计划,是掌握和判断数据库性能的基本技巧.下面案例介绍了多种查看sql执行计划的方式: 基本有以下几种方式: ...
- Netty 能做什么
作为一个学Java的,如果没有研究过Netty,那么你对Java语言的使用和理解仅仅停留在表面水平,会点SSH,写几个MVC,访问数据库和缓存,这些只是初等Java程序员干的事.如果你要进阶,想了解J ...