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 ...
随机推荐
- win11和win10的快捷键列表
win11特有的快捷键 win键就是图案是windows图标的那个按键 作用 快捷键 打开快速设置,win11是展开音量,wifi,蓝牙的设置项,win10也可以用 win + a 打开通知中心和日历 ...
- MedicalGPT:基于LLaMA-13B的中英医疗问答模型(LoRA)
MedicalGPT:基于LLaMA-13B的中英医疗问答模型(LoRA).实现包括二次预训练.有监督微调.奖励建模.强化学习训练[LLM:含Ziya-LLaMA]. **** 训练医疗大模型,实现包 ...
- 面试谈薪4点博弈策略,将20k谈到28k
薪资谈判本质上是一种博弈,无论是表面谈得好还是实质上谈得好,都需要掌握一些策略 面试薪资怎么谈,您目前的薪资是20k,如果您想要提高到28k,那么请花两分钟看完以下内容.薪资谈判本质上是一种博弈,无论 ...
- .net ELk 成功使用
原文地址: http://t.zoukankan.com/shousiji-p-15222276.html
- centos7.9离线升级openssl和openssh9.2
前言 最近有几台服务器漏扫出了关于openssh的漏洞,升级完后顺便记录一下. 环境 CentOS Linux release 7.9.2009 (Core) 开始升级 准备工作 下载安装包: zli ...
- mermaid图详解(一)流程图|超详细的代码解释
本文参考Github项目 https://github.com/mermaid-js/mermaid/ 前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客 ...
- 常用容器:动态数组array、列表list、队列 queue、map或字典、 集合、栈等等
一般语言都会提供一些逻辑容器的实现,各个语言的实现方式不同:底层的数学算法应该差不多: 动态数组 `` 这个没啥可说的,就是一个数组,满了时候,再创建一个数组,把之前的数组里的数据移过来,销毁之前数组 ...
- TfrxReport.Clear。尽量慎用。
for MyXuHaoKey in MyXuHaoJianRongSanJieKouDataDicApi.KeySortList do begin //标记下打印编号,吸入淘打的客户 MyTradeA ...
- TPopupMenu 替换 自身自动的 热键
有时候自动生成的热键 并不是 很理想 这个时候 需要 用自己认为好的 方法如下图,加个(&热键)
- Kubernetes 1.26.0实战:在本地配置k8s集群
阶段一:开发环境及版本 以下环境均来自官网: 本地宿主机环境:Windows 10 21H2 64位 虚拟机软件:VMware workstation 15.5 pro 虚拟机镜像版本:ubuntu- ...