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. 从零开始配置 vim(17)——快捷键提示

    之前我们定义了各种各样的快捷键,有为了增强功能自定义的,有针对插件的.数量一多有的时候就不那么容易记忆了.要是每次要去配置文件找我定义了哪些快捷键肯定会影响使用的. 本篇将要介绍一个插件,它是快捷键的 ...

  2. 【Jmeter】按比例分配Api压测

    先看 [Jmeter]基础介绍-详细 [Jmeter]Request1输出作为Request2输入-后置处理器 继续聊提出的第二个问题,即 2.需要按比例分配API请求并发,以模拟真实的API压力场景 ...

  3. 【一】tensorflow【cpu/gpu、cuda、cudnn】全网最详细安装、常用python镜像源、tensorflow 深度学习强化学习教学

    相关文章: [一]tensorflow安装.常用python镜像源.tensorflow 深度学习强化学习教学 [二]tensorflow调试报错.tensorflow 深度学习强化学习教学 [三]t ...

  4. 【深度学习项目三】ResNet50多分类任务【十二生肖分类】

    相关文章: [深度学习项目一]全连接神经网络实现mnist数字识别 [深度学习项目二]卷积神经网络LeNet实现minst数字识别 [深度学习项目三]ResNet50多分类任务[十二生肖分类] 『深度 ...

  5. [Java] 解析Xml配置文件

    1.解析方法 import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;impo ...

  6. [vue] 脚手架笔记

    笔记 脚手架文件结构 ├── node_modules ├── public │ ├── favicon.ico: 页签图标 │ └── index.html: 主页面 ├── src │ ├── a ...

  7. iOS转场之present与dismiss的使用

    present的使用方式 present只能是A present B , B present C , C present D这样的链式弹出. 不能A present B , A present C , ...

  8. Python-wxauto微信自动发送消息或文件

    1.安装wxauto和pyautogui库,pip安装即可. pip install wxauto pip install pyautogui 2.登录电脑微信客户端 这里有两个注意点:(1)不能将客 ...

  9. JS leetcode 反转字符串 题解分析

    壹 ❀ 引 今天做的一道题非常简单,原题来自leetcode第344题反转字符串,题目如下: 编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出. 不要给另外 ...

  10. NC16681 [NOIP2003]加分二叉树

    题目链接 题目 题目描述 ​ 设一个n个节点的二叉树tree的中序遍历为(l,2,3,-,n),其中数字1,2,3,-,n为节点编号.每个节点都有一个分数(均为正整数),记第j个节点的分数为di,tr ...