【CodeForces训练记录】Codeforces Round 997 (Div. 2)
训练情况
赛后反思
A题犯蠢了,题目看成面积了,C题应该可以更快的搓出来,只能说结论猜了几次不对
A题
我们把周长移动一下,补成一个长方形,左下角的坐标为 \((x_1,y_1)\),右上角坐标为 \((\sum{x_i}+m,\sum{y_i}+m)\),已知两点直接求周长
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
void solve(){
int n,m; cin>>n>>m;
int xx=0,yy=0;
int xxx=0,yyy=0;
for(int i = 1;i<=n;i++){
int x,y; cin>>x>>y;
if(i==1) xxx=x,yyy=y;
xx+=x; yy+=y;
}
cout<<((xx+m-xxx)+(yy+m-yyy))*2<<endl;
}
signed main(){
int T; cin>>T; while(T--)
solve();
return 0;
}
C题
因为需要回文子序列尽可能多,所以我们构造的回文子序列长度要尽可能短
考虑如下构造,把 1
放在两边
1 2 3 4 5 6 7 8 9 1
这种,我们发现回文子序列个数只有 n-2 个,还不够,但是我们可以再凑,把 n-2
位置改成 1
1 2 3 4 5 6 7 1 9 1
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
void solve(){
int n; cin>>n;
vector<int> a(n + 1);
a[1] = 1; a[n] = 1;
for(int i = 2;i<n;i++) a[i] = i;
a[n-1] = n;
a[n-2] = 1;
for(int i = 1;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}
signed main(){
int T; cin>>T; while(T--)
solve();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】