Educational Codeforces Round 124 (Rated for Div. 2)
Dashboard - Educational Codeforces Round 124 (Rated for Div. 2) - Codeforceshttps://codeforces.com/contest/1651
A. Playoff
签到题,第一轮以后剩下的都是奇数,奇数又取最大,答案就是2的n次方-1
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'const int maxn = 0;
const int mod = 1e7+9;int main(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);int t;cin>>t;while(t--){int n;cin>>n;long long ans = pow(2,n)-1;cout<<ans<<endl;}
}
B. Prove Him Wrong
公式推导一下,如果YES,那么必然是x1+x2>=2(x2-x1),也就是3x1>=x2,能尽可能让范围在数据内的情况是1 3 9....打个表n<20的时候最后的数在1e9以内
#include<bits/stdc++.h> using namespace std; #define endl '\n'const int maxn = 0; const int mod = 1e7+9;int main(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);int t;cin>>t;while(t--){int n;cin>>n;if(n>=20)cout<<"NO"<<endl;else{cout<<"YES"<<endl;int a = 1;for(int i = 1;i<=n;i++) {cout << a << " ";a *= 3;}cout<<endl;}} }
C. Fault-tolerant Network
让首尾的度都变成2就可以了,由此推出七种情况(具体看代码吧)
#include<bits/stdc++.h> using namespace std; #define endl '\n'const int maxn = 2e5+10; const int mod = 1e7+9; int a[maxn] = {}; int b[maxn] = {};int main(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);int t;cin>>t;while(t--){int n;cin>>n;for(int i = 1;i<=n;i++)cin>>a[i];for(int i = 1;i<=n;i++)cin>>b[i];long long ad1 = 1e9+10,ad2 = 1e9+10; //首尾到其他点的距离long long bd1 = 1e9+10,bd2 = 1e9+10; //首尾到其他点的距离long long abh = -1,abw = -1; //首首和尾尾long long abhw = -1,abwh = -1;//首尾和尾首abh = abs(a[1]-b[1]);abw = abs(a[n]-b[n]);abhw = abs(a[1]-b[n]);abwh = abs(b[1]-a[n]);for(int i = 1;i<=n;i++){long long d = abs(a[1]-b[i]);ad1 = min(ad1,d); //首到其他d = abs(a[n]-b[i]);ad2 = min(ad2,d);}for(int i = 1;i<=n;i++){long long d = abs(b[1]-a[i]);bd1 = min(bd1,d);d = abs(b[n]-a[i]);bd2 = min(bd2,d);}// cout<<ad1<<" "<<ad2<<" "<<bd1<<" "<<bd2<<" "<<abh<<" "<<abw<<" "<<abhw<<" "<<abwh<<endl;long long ans = min(abhw+abwh,abh+abw);ans = min(ans,abh+ad2+bd2); //首首连ans = min(ans,abw+ad1+bd1);ans = min(ans,abhw+ad2+bd1);ans = min(ans,abwh+ad1+bd2);ans = min(ans,ad1+ad2+bd1+bd2);cout<<ans<<endl;} }
D. Nearest Excluded Points
多源bfs,目的就是减少单点bfs的反复搜索,由贪心思路可知,两种情况,一种是身边有空的,那么答案就是空的,一种是身边没有空的,那么必然它的答案是身边的某一非空点的答案,再使用队列保证一旦找到就是最近距离之一即可。
#include <bits/stdc++.h>#define INF 0x3f3f3f3f typedef long long ll; using namespace std; const int maxn = 2e5+10; pair<int,int>p[maxn]; map<pair<int,int>,pair<int,int>>ans; set<pair<int,int>>vis; queue<pair<int,int>>q; pair<int,int>now; pair<int,int>nex; int dx[] = {0,0,0,1,-1}; int dy[] = {0,1,-1,0,0};void bfs(){while(!q.empty()){now = q.front();q.pop();for(int i = 1;i<=4;i++){nex = {now.first+dx[i],now.second+dy[i]};if(vis.count(nex)&&!ans.count(nex)){ //被围死的点的答案和被围着的某个点一样ans[nex] = ans[now];q.push(nex);}}} }int main() {int n;cin>>n;for(int i = 1;i<=n;i++)cin >> p[i].first >> p[i].second;for(int i = 1;i<=n;i++)vis.insert(p[i]);/*for(int i = 1;i<=n;i++)cout<<p[i].first<<" "<<p[i].second<<endl;*/for(int i = 1;i<=n;i++){for(int j = 1;j<=4;j++) {now = {p[i].first + dx[j], p[i].second + dy[j]};if(!vis.count(now)) {ans[p[i]] = now;q.push(p[i]);break;}}}bfs();for(int i = 1;i<=n;i++)cout<<ans[p[i]].first<<" "<<ans[p[i]].second<<endl; }
加油
Educational Codeforces Round 124 (Rated for Div. 2)相关推荐
- Educational Codeforces Round 124 (Rated for Div. 2)D. Nearest Excluded Points
一开始从标记点开始bfs ole 了,然后从空点开始就过了 原题链接Problem - D - Codeforces #include<iostream> #include<queu ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
- Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs
传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...
- Educational Codeforces Round 72 (Rated for Div. 2) D. Coloring Edges dfs树/拓扑找环
传送门 文章目录 题意: 思路: 题意: 给你一张图,你需要给这个图的边染色,保证如果有环那么这个环内边的颜色不全相同,输出染色方案和用的颜色个数. n,m≤5e3n,m\le5e3n,m≤5e3 思 ...
- Educational Codeforces Round 111 (Rated for Div. 2) D. Excellent Arrays 组合数学
传送门 文章目录 题意: 思路: 题意: 给你一个数组aia_iai,定义一个数组是好的当且仅当对于所有iii都有ai!=ia_i!=iai!=i.定义f(a)f(a)f(a)表示数组aaa中i& ...
最新文章
- 前端Vue学习之路(四)axios请求数据
- 【算法学习笔记】57. 前缀树 字典序优化技巧 STL学习 SJTU OJ 1366 前缀匹配
- 【收藏】Linux系统常用命令速查手册(附PDF下载链接)
- IOS-字符串太长换行拼接
- html5 --- 使用canvas画一个渐变矩形
- java 主方法 this_java main 方法怎么创建
- php点链接直接现在文件吗,PHP实现点击a标签的href做链接时,直接保存文件(任何类型),而...
- acctype mysql assoc_dedeCMS数据库类的一些常见的使用方法
- mysql备份恢复中的常见错误
- java人事考勤打卡小程序源码
- 大学生创新创业企划书
- matlab 小波分析实例,小波分析MATLAB实例
- f452虚拟服务器,中兴f452网关,超级用户的密码如何获得,启动路由功能
- 什么软件测试显示器响应时间准,液晶响应时间测试系统
- Redis之listpack、rax
- 关于功能结构图 信息结构图 产品结构图那点小事
- 高分一号、二号样例数据下载
- 英语和计算机水平,关于我的英语和计算机水平的分析
- docker 简单教程
- 解决白盒、mock、性能、自动化测试脚本中的数据自动生成问题——Spock-Genesis
热门文章
- 2022-10-31 网工进阶(三十三) IP组播-流量模型、组播概念、组播报文结构、组播地址与MAC、组播网络架构、组播服务模型、组播数据转发原理(RPF检查、组播分发树、组播协议介绍)
- Kotlin Language
- JQuery知识点整理
- 看完这篇 教你玩转渗透测试靶机vulnhub——DC3
- Django Model 2.数据库—多表查询
- 古典密码-凯撒加密和解密
- 只有你项目不到,Electron也可以开发视频播放器
- Famp;amp;C游戏推荐Canvas2~茜色的调色盘~~茜色のパレット~介绍下载
- PTA-幂级数展开的部分和
- android自动化解锁,Android唤醒、解锁屏幕代码实例