Codeforces Round #614 (Div. 2)
A. ConneR and the A.R.C. Markland-N (CF 1293 A)
题目大意
层楼,每层都有个餐厅,但有个餐厅不开放,分别在层,在第层,现在他要去吃午饭,问他去餐厅最小的跨楼层是多少?
解题思路
巨大但很小,用储存,拿两个指针从往上往下扫到没有关闭的餐厅的即可。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) using namespace std; typedef long long LL; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int kase; cin>>kase; for (int i = 1; i <= kase; i++) { int n,s,k; cin>>n>>s>>k; set<int> qwq; for(int u,i=1;i<=k;++i){ cin>>u; qwq.insert(u); } int l=s; int r=s; while(true){ if (l>=1) if (qwq.find(l)!=qwq.end()) --l; else break; if (r<=n) if (qwq.find(r)!=qwq.end()) ++r; else break; } int ans=0; if (l==0) ans=r-s; else if (r==n+1) ans=s-l; else ans=min(s-l,r-s); cout<<ans<<endl; } return 0; }
B. JOE is on TV! (CF 1293 B)
题目大意
初始个对手,答题,答错出局,某个回合,还有个对手,若该回合有个对手答错,则你可以获得。问你可能获得的最大美元数是多少?
解题思路
经过数次枚举我们可以猜想每次一个人答错,最终获得的美元数最多,以下为证明:
设当前有位选手,若当前回有位选手答错,则获得的美元为,由于,故,所以每次位选手答错时最终所得的美元数是最大的。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) using namespace std; typedef long long LL; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (s) x = -x; } template <typename T> void write(T x, char c = ' ') { int b[40], l = 0; if (x < 0) putchar(45), x = -x; while (x > 0) b[l++] = x % 10, x /= 10; if (!l) putchar(48); while (l) putchar(b[--l] | 48); putchar(c); } int main(void) { int n; read(n); double ans=0; for(int i=1;i<=n;++i) ans+=1.0/(double)(n-i+1); printf("%.6f\n",ans); return 0; }
C. NEKO's Maze Game (CF 1293 C)
题目大意
给定一个的矩形格子,你要从走到,有个时刻,第个时刻,的格子的状态会翻转,即从可走变不可走,或者不可走变可走。初始所有格子可走,问每一个时刻后,你能否从走到。
解题思路
注意到不能达到的不可走格子分布只有两种,第一种是某一列的两个格子都不可走,第二种是相邻列的不同行格子都不可走,分别统计这两种的分布的数量,大于则不可到达,否则可以到达。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) using namespace std; typedef long long LL; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (s) x = -x; } template <typename T> void write(T x, char c = ' ') { int b[40], l = 0; if (x < 0) putchar(45), x = -x; while (x > 0) b[l++] = x % 10, x /= 10; if (!l) putchar(48); while (l) putchar(b[--l] | 48); putchar(c); } const int N=1e5+8; int val[2][N],cnt,n,q; int main(void) { read(n); read(q); val[0][0]=val[1][0]=val[0][n+1]=val[1][n+1]=-1; for(int r,c,i=1;i<=q;++i){ read(r); read(c); r--; val[r][c]^=1; if (val[r][c]==1&&val[r^1][c]==1) ++cnt; if (val[r][c]==0&&val[r^1][c]==1) --cnt; if (val[r][c]==1&&val[r^1][c-1]==1) ++cnt; if (val[r][c]==0&&val[r^1][c-1]==1) --cnt; if (val[r][c]==1&&val[r^1][c+1]==1) ++cnt; if (val[r][c]==0&&val[r^1][c+1]==1) --cnt; if (cnt) puts("No"); else puts("Yes"); } return 0; }
D. Aroma's Search (CF 1293 D)
题目大意
给定一个坐标,有好多数据包,初始数据包在位置处,之后的数据包由递推式给出,第个数据包编号为,坐标为。的初始位置是,它可以上下左右移动次,问他最多能搜集到多少数据包。
解题思路
注意到都大于,那些数据包的坐标会越来越大,它们的距离也会越来越大,故当到达某个数据包时,显然我们是往标号小的数据包去跑是最好的。第个数据包和第个数据包的曼哈顿距离为,极端情况下即是的时候,这时候距离就是,由于,所以数据包的坐标我们就枚举到即可,由于递推式里坐标是指数级增长的,枚举到的数据包最多也就个,妥妥暴力枚举第一个到达的数据包编号贪心求数量取最大值即可。注意如果先到达第个数据包,最后到了第个数据包还可以继续移动的话,还要继续枚举第个数据包及以上看能否到达。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) using namespace std; typedef long long LL; const LL N=10000000000000000ll+8; vector<pair<LL,LL>> pos; int check(int x,LL xs,LL ys,LL t){ int cnt=0; for(int i=x;i>=0;--i){ LL dis=abs(pos[i].first-xs)+abs(pos[i].second-ys); if (dis<=t){ t-=dis; xs=pos[i].first; ys=pos[i].second; ++cnt; } else return cnt; } int len=pos.size(); for(int i=x+1;i<len;++i){ LL dis=abs(pos[i].first-xs)+abs(pos[i].second-ys); if (dis<=t){ t-=dis; xs=pos[i].first; ys=pos[i].second; ++cnt; } else return cnt; } return cnt; } int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); LL x0,y0,ax,ay,bx,by; cin>>x0>>y0>>ax>>ay>>bx>>by; LL xs,ys,t; cin>>xs>>ys>>t; pos.push_back(make_pair(x0,y0)); while(x0<N||y0<N){ if (x0>=ax*x0+bx) break; x0=ax*x0+bx; if (y0>=ay*y0+by) break; y0=ay*y0+by; pos.push_back(make_pair(x0,y0)); } int ans=0; int len=pos.size(); for(int i=0;i<len;++i) ans=max(ans,check(i,xs,ys,t)); cout<<ans<<endl; return 0; }
~~第一次交MLE怀疑人生??我就53个点怎么MLE??后来发觉是long long溢出导致枚举数据包停不下来了~~
本文作者:~Lanly~
本文链接:https://www.cnblogs.com/Lanly/p/12216093.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现