(CodeForce) Codeforces Round #541 (Div. 2) A,B,C,D,F

2024-03-20 17:18

本文主要是介绍(CodeForce) Codeforces Round #541 (Div. 2) A,B,C,D,F,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

传送门

A. Sea Battle

:围成的不规则图像的周长(就是矩形的周长),在加四个角重复的部分。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
ll w1,h1,w2,h2;
int main(){std::ios::sync_with_stdio(0);cin>>w1>>h1>>w2>>h2;ll sum=(h1+h2)*2+(max(w1,w2))*2+4;cout<<sum<<endl;return 0;
}

B. Draw! 

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int maxn=1e4+50;
ll a[maxn],b[maxn],le,ri;
int main() {std::ios::sync_with_stdio(0);int n;ll ans=0,tdd=-1;cin>>n;for(int i=1; i<=n; ++i) {cin>>a[i]>>b[i];}for(int i=1; i<=n; ++i) {le=max(a[i-1],b[i-1]);ri=min(a[i],b[i]);if(ri>=le) ans+=ri-max(le-1,tdd),tdd=max(le,ri);}cout<<ans<<endl;return 0;
}

C. Birthday 

:只要序列高度(大小)是一个山字形就行了,所以排个序,操作一下就行

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int maxn=1005;
int n;
int a[maxn];
vector<int> ans;
int main() {std::ios::sync_with_stdio(0);cin>>n;for(int i=0; i<n; ++i)	cin>>a[i];sort(a,a+n);for(int i=n-1; i>=0; --i) {if(i&1)	ans.insert(ans.begin(),a[i]);else	ans.insert(ans.end(),a[i]);}for(int i=0; i<(int)ans.size(); ++i) {cout<<ans[i]<<" ";}cout<<endl;return 0;
}

D. Gourmet choice

单独写了戳我

F. Asya And Kittens

:这也是一个并查集的题目,我们只需将每次合并的东西维护一下,这题就迎刃而解了

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int maxn=155000;
int fa[maxn],rk[maxn]; //这里的rk是 以i为父亲为集合的元素
vector<int> G[maxn];
int find(int x) {if(fa[x]==x)	return fa[x];else	return fa[x]=find(fa[x]);
}
void unity(int x,int y) {x=find(x),y=find(y);if(x==y) return;if(rk[x]<rk[y]) swap(x,y);fa[y]=x,rk[x]+=rk[y];for(int i=0; i<=rk[y]-1; ++i) { //每次合并我们把集合的元素也并一下G[x].push_back(G[y][i]);}
}
int n;
int main() {std::ios::sync_with_stdio(0);cin>>n;for(int i=1; i<=n; ++i)fa[i]=i,G[i].push_back(i),rk[i]=1;int x,y;for(int i=1; i<=n-1; ++i) {cin>>x>>y;unity(x,y);}int st=find(1);for(int i=0; i<=n-2; ++i) {cout<<G[st][i]<<' ';}cout<<G[st][n-1]<<endl;return 0;
}

 

 

 

 

 

这篇关于(CodeForce) Codeforces Round #541 (Div. 2) A,B,C,D,F的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/830193

相关文章

Codeforces 158B

很久没有刷题了,刚刚有小学弟问了这道题,AC之后贴上来吧。水~~~ #include <cstdio>#include <cmath>int main() {int n;while(scanf("%d", &n) != EOF) {int a = 0, b = 0, c = 0, d = 0;int arr[100001];for (int i = 0; i < n; ++

Codeforces April Fools Day Contest 2014(附官方题解)

Codeforces2014年愚人节的坑题。。。但还是感觉挺好玩的。。。 A. The Great Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two teams mee

Codeforces April Fools Day Contest 2013

2013年愚人节的坑题。。。 A. Mysterious strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Input The input contains a sin

力扣SQL50 项目员工 I ROUND AVG

Problem: 1075. 项目员工 I 👨‍🏫 参考题解 Code select project_id,ROUND(AVG(e.experience_years),2) as average_yearsFROMproject as pLEFT JOINemployee as eONp.employee_id = e.employee_idGROUP BYp.proje

[Codeforces 451B] Sort the Array (实现)

Codeforces - 451B 给定一个序列,其中每个数都不相同 问是否能在翻转其中一段后,整个序列变得单调递增 实现题 首先设一个 B B数组为 AA数组排序后的结果 由于只能翻转一个区间,那么我假装 A是满足要求的 找到最小的 A[l]≠B[l] A[l] \ne B[l],最大的 A[r]≠B[r] A[r] \ne B[r], 翻转的区间将会是 [l,r

[Codeforces 451A] Game With Sticks (博弈)

Codeforces - 451A N根横向木棍,M根纵向木棍组成了一个网格图 每次可以选择一个交点,去掉所有通过这个交点的木棍 两个人交替进行这个游戏,问最后谁能胜利 每次选择的一个交点,必然去掉了一根横向木棍和纵向木棍 所以每次 N和 M都减一 当其中有一个为 0的时候,就是先手必败态 所以只和 N、M中较小的那个的奇偶性有关 #pragma comment(link

[Codeforces 166B] Polygons (点在凸多边形内)

Codeforces - 166B 判断任意多边形 B是否严格在凸多边形 A内部 点在凸多边形内部试板题 如果 B的所有顶点在 A内,则 B在 A内 由于 A的顶点有 105 10^5个,B的顶点有 104 10^4 个 所以不能用 (n) \mathcal{O}(n)的暴力判断 有一个 (logn) \mathcal{O}(logn) 的二分做法 基本原理是用

[Codeforces - Gym10081D (NEERC)] Distribution in Metagonia (构造+数的拆分)

Codeforces - Gym10081D (NEERC) 给定一个数,将其变成若干个数的和 如果这些数有因子,那么只能是 2或 3 并且这些数两两不能除尽 构造题 如果这个数为 1,那么答案就为 1 若不为 1,那么如果他是奇数 那么我减去最大的一个 3次幂转化为一个偶数, 再不断地提出 2,变成一个奇数,循环直到其变为 1 所以这个数 N=3a1+2b1(3a2

[Codeforces - Gym100801H (NEERC)] Hash Code Hacker (字符串构造)

Codeforces - Gym100801H (NEERC) 给定一个字符串hash,为 ∑i=0len−1str[i]×31len−1−i \displaystyle\sum_{i=0}^{len-1} str[i]\times 31^{len-1-i} 求 K K个长度不超过 1000的字符串,使得他们的 hash值相等 其中每个 hash值是 32位有符号整数,K≤1000K\l

HTML页面布局-使用div示例

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><!--text-align:center 文字水平居中line-height:200px; 文字垂直居中,行高设置跟高度一样,文字就会在当前div中水平居中margin:0 auto 在页面水平居中-