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)补题的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  3. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  4. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  5. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  6. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  7. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  8. 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 ...

  9. Codeforces Round #282 (Div. 1) A. Treasure 水题

    A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...

  10. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

随机推荐

  1. gRPC如何保障数据安全传输

    什么是 gRPC? gRPC 是由 Google 开发的高性能.开源的 RPC(Remote Procedure Call)框架,用于在客户端和服务器之间进行通信.它基于 Protocol Buffe ...

  2. 从零开始配置 vim(10)——快捷键配置

    之前我们对neovim 进行了基础的配置,这篇主要介绍我比较常用的快捷键配置.到这篇开始我们的配置已经可以为两个大的模块--基础配置和快捷键配置.我们的目录也应该按照模块来进行组织.在正式配置之前让我 ...

  3. 【CSDN浏览器插件测评超详细版】——万能便捷的C功能,直接爱不释手,强烈推荐!更多功能等你探索

    我的界面预览: 1.下载安装 下载链接:https://plugin.csdn.net/?utm_source=chajian-contest-1210#/chrome-index-help 说明:若 ...

  4. C/C++可变参数模版和函数指针的结合

    目录 1.说明 2.模板类传入固定参数的C函数指针 3.模板类传入固定参数的C++函数指针 3.1.用函数对象替代函数指针存储 4.模板类传入不定参数的C函数指针 5.模板类传入不定参数的C++成员函 ...

  5. 顶配涨至近2万 该买还是买!iPhone15正面曝光 与历代苹果手机对比边框爆窄

    从曝光的iPhone 15正面渲染图来看,其颜值确实要比上代又提高不少. 外媒放出了一组iPhone 15 Pro的正面渲染图照,从图片看边框非常的窄,与历代iPhone 边框对比,这个特点更是被放大 ...

  6. JVM(Java虚拟机)整理(二)

    前言 上一篇内容:JVM(Java虚拟机)整理(一)https://www.cnblogs.com/xiegongzi/p/17994659 Java 内存模型(JMM) Java 内存模型引入 声明 ...

  7. python 中异常类型总结

    异常类型: 异常名称 描述BaseException             所有异常的基类SystemExit                   解释器请求退出KeyboardInterrupt  ...

  8. 【framework】RootWindowContainer简介

    1 前言 ​ RootWindowContainer 是窗口容器的根容器,子容器是 DisplayContent.关于其父类及祖父类的介绍,见→WindowContainer简介.Configurat ...

  9. 【framework】WindowContainer简介

    1 前言 ​ WindowContainer 继承自 ConfigurationContainer,是 WMS 家族的重要基类.ConfigurationContainer简介 中,已介绍 Confi ...

  10. 解决SQLyog连接mysql报错:Your password has expired

    解决步骤如下: D:\program\mysql-5.7.16-winx64\bin>mysql -uroot -p Enter password: ******* Welcome to the ...