Educational Codeforces Round 101

1|0C. Building a Fence


首先相邻的两个栅栏是否相交的判断可以转换为两个栅栏的底的距离差,这样实际上我们并不需要维护出栅栏,只需要维护底的位置即可。

假设上一个栅栏可摆放的位置是[x,y],则与之相交的栅栏应该摆放在[xk+1,y+k1]。如果当前地面高度是h,则当前栅栏可摆放的位置就是[h+1,h+k]。两个区间的交集就是当前栅栏能摆放的合法区间。

#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18; void solve() { int n, k, x, y; cin >> n >> k; vector<int> h(n); for (auto &i: h) cin >> i; x = y = h[0] + 1; for (int i = 1, l, r, p, q; i < n - 1; i++) { l = x - k + 1, r = y + k - 1; p = h[i] + 1, q = h[i] + k; x = max( l , p ) , y = min( r , q ); if( x > y ) { cout << "NO\n"; return; } } if( x - k + 1 <= h.back()+1 and h.back()+1 <= y + k - 1 ) cout << "YES\n"; else cout << "NO\n"; } int32_t main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; for (; t; t--) solve(); return 0; }

2|0D. Ceil Divisions


构造题,首先1,2不需要操作。把出了8,n以外的数字全部除以n,在把n除以8,最后把8除以2即可。

#include <bits/stdc++.h> using namespace std; #define int long long using pii = pair<int, int>; void solve() { int n; cin >> n; vector<pii> res; for (int i = 3; i < n; i++) if (i != 8)res.emplace_back(i, n); if (n > 8) { for (int x = n; x > 1; x = (x + 7) / 8) res.emplace_back(n, 8); for (int x = 8; x > 1; x = (x + 1) / 2) res.emplace_back(8, 2); } else { for( int x = n ; x > 1 ; x = ( x + 1 ) / 2) res.emplace_back( n , 2 ); } cout << res.size() << "\n"; for( auto [x,y] : res ) cout << x << " " << y << "\n"; return ; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0); int t; for (cin >> t; t; t--) solve(); return 0; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17702986.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示