Codeforces Round 982 (Div. 2)
A. Rectangle Arrangement
题目
给定
分析
乍一看并没有什么思路,但是写出这个题并不难,案例很好的提示了我们要将所有矩形一角放一起,那么最后就会组成一个阶梯形状的图案,使用割补法,这个图形周长等价与
得到结论后,就很好理解为什么这样摆放矩形为什么是周长最小
首先,最大的长和最大的宽这两个矩形,最好的方式就是放在一个长为
然后将其他的矩形全部放进去,周长不变(反向割补法)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
//vector<vector<int>>adj(N);
void solve()
{
int n; cin >> n;
int maxx = 0, maxy = 0;
for(int i = 1; i <= n; i ++) {
int x, y;
cin >> x >> y;
maxx = max(maxx, x);
maxy = max(maxy, y);
}
cout << 2 * (maxx + maxy) << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
}
B. Stalin Sort
分析
枚举a数组中每一个元素作为脆弱数组中第一个元素
那么需要从a数组中删除两类数
- 在这个元素前面的所有数
- 在一个元素后面的所有比他大的数(这种数不能通过题目的操作删掉)
删掉这两种数后,脆弱数组中第一个元素最大,使用题目操作可以删掉后面全部的数
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
//vector<vector<int>>adj(N);
void solve()
{
int n; cin >> n;
vector<int> a;
for(int i = 0; i < n; i ++) {
int x; cin >> x;
a.push_back(x);
}
int ans = INF;
for(int i = 0; i < n; i ++) {
int res = 0;
for(int j = 0; j < n; j ++) {
if(j < i || a[j] > a[i]) res ++;
}
ans = min(res, ans);
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
}
C. Add Zeros
感觉BC应该调换一下位置
分析
对于
所以让
表示数组长度可以从
那么起点就是
因为新加的数是
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
// vector<vector<int>>adj(N);
map<ll,vector<ll>> adj;
map<ll,bool> vis;
ll ans = 0;
void dfs(ll u) {
ans = max(u, ans);
if(vis[u]) return;
vis[u] = true;
for(auto v : adj[u]) {
dfs(v);
}
}
void solve()
{
int n; cin >> n;
for(int i = 1; i <= n; i ++) {
ll x; cin >> x;
if(i != 1) {
ll u = x + i - 1;
ll v = u + i - 1;
adj[u].push_back(v);
}
}
dfs(n);
cout << ans << endl;
ans = 0;
adj.clear();
vis.clear();
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】