Codeforces Round 922 (Div. 2)(A~D)补题
A题考虑贪心,要使使用的砖头越多,每块转的k应尽可能小,最小取2,最后可能多出来,多出来的就是最后一块k=3,我们一行内用到的砖头就是\(\frac{m}{2}\)下取整,然后乘以行数就是答案。
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
#define int long long
using namespace std;
const int N=2e5+10;
vector<int>s[N];
int u[N],ans[N];
void solve()
{
int n,m;cin>>n>>m;
cout<<m/2*n<<endl;
}
signed main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
B题就是猜的一个排序,\(对于i,a[i]+b[i]越大我们就考虑将他往后放,有一点贪心的思想吧,如果a[i]+b[i]越大放在前面产生的逆序对可能就越多,所以我们考虑将大的往后放\)
b题wa了两发,第一次是排序的时候弄反了。
第二次写排序函数的时候降序就写\(<不要写<=,写了<= re了\)
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
//#define int long long
using namespace std;
const int N=2e5+10;
struct node
{
int a,b,sum;
}kk[N];
bool cmp(node t1,node t2)
{
return t1.sum<t2.sum;
}
void solve()
{
int n;cin>>n;
rep(i,1,n) cin>>kk[i].a;
rep(i,1,n) cin>>kk[i].b;
rep(i,1,n) kk[i].sum=kk[i].a+kk[i].b;
sort(kk+1,kk+1+n,cmp);
rep(i,1,n) cout<<kk[i].a<<' ';
cout<<endl;
rep(i,1,n) cout<<kk[i].b<<' ';
cout<<endl;
}
signed main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
c题是位运算+贪心
一般1e18很可能就是\(log\)的算法,涉及到异或这些很可能就是要考虑每一位的影响。
这道题就是需要考虑每一位对答案的贡献,这种贡献法也是很常用的思考方式。
赛时有框架了,但是贪心的细节没考虑好没过。
大佬指导的是位运算很多时候需要考虑贪心,因为位与位之间独立。
我们考虑如果a,b两个数的二进制下第i位
\(当a_i=b_i时无论x取何值这一位对答案的贡献都是0,我们就然x的这一位为0因为x要小于r,x后面会有用\)
\(当a_i\not=b_i时这时看x_i=1是否能然答案变小,如果可以就让x_i=1否则就然x_i=0\)
\(x_i=1需要建立在x<r的前提下\)
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
#define int long long
using namespace std;
const int N=64;
int work(int x,int i)
{
return x&(1ll<<i);
}
void solve()
{
int a,b,r;cin>>a>>b>>r;
if(a<b) swap(a,b);
int ans=0;
fep(i,60,0)
{
if(work(a,i)==work(b,i)) continue;
if(r>=(1ll<<i))
{
int kk=abs(ans+(work(a,i)^(1ll<<i))-(work(b,i)^(1ll<<i)));
if(kk<abs(ans))
{
ans=kk;
r-=(1ll<<i);
}
else ans+=(work(a,i)^0)-(work(b,i)^0);
}
else ans+=(work(a,i)^0)-(work(b,i)^0);
}
cout<<abs(ans)<<endl;
}
signed main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
D
二分+大根堆优化dp
首先需要二分答案,在b站的一个up看的讲解b站的up讲解
这种题目就是可以通过二分答案然后变成简单的check。
接下来需要考虑如何check,由于我们删数的位置不确定,同时我们需要求的是在满足一定条件下的最优化问题,这时我们可以考虑一下dp
\(f[i]表示处理好的前i个(前i个的区间间隔均<mid)\)
\(并且删除第i个元素,所有删除元素的和的最小值\)
\(考虑转移:f[i]=f[k]+a[i],其中k是满足区间和小于mid的f中的最小值\)
\(我们可以看到枚举状态O(n),枚举转移也需要O(n),这样复杂度就是O(n^2logn)\)
\(考虑优化可以用优先队列维护和双指针维护满足条件的区间,以及区间内的f的最小值\)
\(由于状态的设计所以状态需要计算到n+1,因为n有删或不删两种情况,这是一个常用的小技巧\)
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
using namespace std;
const int N=1e5+10;
int n,a[N],f[N];
bool check(int x)
{
priority_queue<pll,vector<pll>,greater<pll>>q;
int l=0,ss=0;
q.push({0,0});
rep(i,1,n+1)
{
while(l<i&&ss>x)
{
ss-=a[l];
l++;
}
while(q.size()&&q.top().y<l-1) q.pop();
f[i]=q.top().x+a[i];
q.push({f[i],i});
ss+=a[i];
}
return f[n+1]<=x;
}
void solve()
{
cin>>n;
rep(i,1,n) cin>>a[i];
a[n+1]=0;
int l=0,r=1e15;
while(l<r)
{
int mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<l<<endl;
rep(i,0,n+1) f[i]=0;
}
signed main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
Codeforces Round 922 (Div. 2)(A~D)补题的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #426 (Div. 2)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #282 (Div. 1) A. Treasure 水题
A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...
- Codeforces Round #327 (Div. 2) B. Rebranding 水题
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...
随机推荐
- git checkout switch restore
前言 在 Git 术语中,"checkout"是在目标实体的不同版本之间切换的行为.该命令对三个不同的实体进行操作:文件.提交和分支.除了"checkout"的 ...
- 小白学k8s(10)-k8s中ConfigMap理解
理解ConfigMap 什么是ConfigMap ConfigMap的创建 使用key-value 字符串创建 从env文件创建 从目录创建 通过Yaml/Json创建 ConfigMap使用 用作环 ...
- Linux 文件目录压缩与解压命令
Linux 文件目录压缩与解压命令,融合多部Linux经典著作,去除多余部分,保留实用部分. compress压缩: compress是个历史悠久的压缩程序,文件经它压缩后,其名称后面会多出 &quo ...
- OpenGL的模板缓冲
注意看,利用OpenGL的模板缓冲,可以轻松实现很多酷炫的效果.当然,它用起来也很简单.下面就跟着博主小编,一起来看看吧! 模板缓冲的使用 假设有个大小为800x600的窗口,那么模板缓冲也是 ...
- 【题解】P9749 [CSP-J 2023] 公路
\(Meaning\) \(Solution\) 这道题我来讲一个不一样的解法:\(dp\) 在写 \(dp\) 之前,我们需要明确以下几个东西:状态的表示,状态转移方程,边界条件和答案的表示. 状态 ...
- Hadoop-Operation category READ is not supported in state standby 故障解决
在查询hdfs时或者执行程序向hdfs写入数据时遇到报错:Operation category READ is not supported in state standby 意思是:该主机状态为待机, ...
- Windows终端的一些配置
前言 记录早前拿到新的笔记本(win10)后配置命令行的过程,以下是环境: 命令行 : CMD,PowerShell7 Shell :Windows Terminal 设置编码格式(当前代码页)为UT ...
- win10 通过 ssh 连接云服务器失败 are too open. bad permissions.
最近突然想起了自己的学生机服务器,买来了吃灰很久了,拿出来捣鼓捣鼓 以前服务器装的 windows server,这次把它重装成了 CentOS 8.0,然后按官网步连接步骤骤一步一步尝试. 腾讯云官 ...
- CentOS7环境下编译FFmpeg
操作系统:CentOS 7.6.1810_x64 ffmpeg版本:4.2.1 ffmpeg是一个功能非常强大的音视频处理工具,很多软件依赖它,这里记录下编译过程,以便后续查阅. ffmpeg官方网址 ...
- Sunnyui画曲线溢出错误
之前用sunnyui做展示数据库数据曲线的时候.偶然会报溢出错误,也不报错错误在哪,就是直接程序都跑不动了. 后面发现 设置曲线上下限的时候,当上下限一样的时候就会导致溢出错误.sunnyui的曲线也 ...