链接:Dashboard - Codeforces Round 922 (Div. 2) - Codeforces
A. Brick Wall
题意:给定一个n*m的区域,求用1*k(k可以变化)的方块去放时,横着放-竖着放的最大值
思路:显然有尽量用横着去铺的想法,那就是都用1*2的方块,如果m是奇数就需要有一块区域是用1*3的
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128 lll;
typedef long double ld;
//#define endl '\n'
#define pii pair<int, int>
const int N = 1e6+8;
const int M = 1e2 + 5;
const ll mod = 1e8+1;
const int inf = 0x3f3f3f3f;
const ll inff = 1e18;
void solve(){
ll x,y;
cin>>x>>y;
if(y%2==1){
cout<<x*(y-3)/2+x<<endl;
}
else cout<<x*(y/2)<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;
T = 1;
cin>>T;
for (int i = 1; i <= T; ++i)
{
solve();
}
//system("pause");
return 0;
}
// 16 6 3 16
B. Minimize Inversions
题意:给出长度为n的序列a和b,可以任意调整a序列中元素位置,但是调整后b也要做出相应的调整,求a,b总共的逆序对最少是多少
思路:将a调整为升序后,b的逆序对数即为答案;反过来想,如果a此时有序,那么调整b有序一对必然会导致a的一对无序,代价不会小于成效。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128 lll;
typedef long double l

文章介绍了五道编程竞赛题目,涉及区间操作、排序、逆序对的最小化、异或距离计算以及任务顺序安排。解决方案展示了如何使用不同的算法策略,如排序、二分查找和数据结构(如小跟堆)来解决这些问题。
最低0.47元/天 解锁文章
794

被折叠的 条评论
为什么被折叠?



