Codeforces Round 922 (Div. 2)
Codeforces Round 922 (Div. 2)
A. Brick Wall
思路
简单的模拟,要想实现最高的稳定性,就横着放就可以了,因为长度必须大于等于2,所以最后即使不能被2整除,也可以算在里面
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n,m;
cin>>n>>m;
int res=m/2*n;
// int
cout<<res<<endl;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t; while(t--)
solve();
return 0;
}
B. Minimize Inversions
思路
比赛时候没有仔细证明,因为a数组和b数组是同时改变的,所以是一对一对改变的,因此我们可以稍微贪心的处理一下
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
int a,b;
node(int x,int y){
a=x;
b=y;
};
friend bool operator < (node x,node y){//利用友元函数来创建
return (x.a+x.b)<(y.a+y.b);
}
};
void solve() {
int n;
cin>>n;
std::vector<int> a(n+1),b(n+1);
vector<node> c;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
for(int i=1;i<=n;i++){
c.push_back(node(a[i],b[i]));
}
sort(c.begin(),c.end());
for(auto x:c){
cout<<x.a<<" ";
}
cout<<endl;
for(auto x:c){
cout<<x.b<<" ";
}
cout<<endl;
return ;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t; while(t--)
solve();
return 0;
}
C. XOR-distance
思路
贪心,当然我这个没做出来,这是ctgg写的solve,我赛后参考了一下
Code
#include<bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
void solve()
{
ll a,b,r;
cin>>a>>b>>r;
if(a>b) swap(a,b);//a<b
int flag=0;
for(int i=60;i>=0;i--)
{
int t1=a>>i&1;
int t2=b>>i&1;
if(t1==t2) continue;
else
{
if(flag==0)
{
flag=1;
continue;
}
if((1ll<<i)>r) continue;
if((a>>i&1)==0&&(b>>i&1)==1)
{
a^=(1ll<<i);
b^=(1ll<<i);
r-=(1ll<<i);
}
}
}
cout<<b-a<<endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
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】