洛谷 P3462 [POI2007]ODW-Weights
题面:
https://www.luogu.org/problemnew/show/P3462
https://www.lydsy.com/JudgeOnline/problem.php?id=1110
https://szkopul.edu.pl/problemset/problem/y7tXjqVq0gPZjc8kPrscs2CJ/site/?key=statement
先打了个贪心。直接所有容器从大到小排序,按这个顺序处理容器,每个容器每次装能够装进且最大的砝码。用multiset维护。
WA了(貌似洛谷还骗到40分?)
然后想了想改了一下。先二分答案,对于每个二分出的答案x显然最好方案是取最小的x个砝码。然后就当做只有这些砝码,用前面的贪心判是否能够取完这些砝码。
错误记录:没有对砝码按重量排序...
A掉了?(n*log^2而且常数大,因此bzojA不掉,其他两个地方可以A)而且貌似容器不排序(甚至random_shuffle)都没有关系?
不太会证..
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int n,m;
int a[],b[];
multiset<int> s;
bool judge(int x)
{
s.clear();
int i,t;multiset<int>::iterator i1;
for(i=;i<=x;++i)
s.insert(b[i]);
for(i=n;i>=;--i)
{
t=a[i];
while(!s.empty()&&((i1=s.upper_bound(t))!=s.begin()))
{
--i1;
t-=*i1;
s.erase(i1);
}
}
return s.empty();
}
int main()
{
int i;
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(i=;i<=m;++i)
scanf("%d",&b[i]);
sort(b+,b+m+);
int l=,r=m,mid;
while(l!=r)
{
mid=l+((r-l)>>);
if(judge(mid+)) l=mid+;
else r=mid;
}
printf("%d",l);
return ;
}
网上有高妙的一个log做法
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int n,m;
int a[],b[],c[];
int d[];
int ans;
void try_work(int p)
{
if(p>c[]) return;
if(d[p]>=)
{
--d[p];
d[p-]+=c[p]/c[p-];
}
else
{
try_work(p+);
if(d[p]>=)
{
--d[p];
d[p-]+=c[p]/c[p-];
}
}
}
int main()
{
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)
scanf("%d",&a[i]);
for(i=;i<=m;++i)
scanf("%d",&b[i]);
sort(b+,b+m+);
for(i=;i<=m;++i)
c[++c[]]=b[i];
c[]=unique(c+,c+c[]+)-c-;
for(i=;i<=n;++i)
for(j=c[];j>=;--j)
{
d[j]+=a[i]/c[j];
a[i]%=c[j];
}
for(i=,j=;i<=m;++i)
{
while(c[j]<b[i]) ++j;
if(d[j]>=)
{
--d[j];
++ans;
}
else
{
try_work(j+);
if(d[j]>=)
{
--d[j];
++ans;
}
}
}
printf("%d",ans);
return ;
}
洛谷 P3462 [POI2007]ODW-Weights的更多相关文章
- [洛谷P3460] [POI2007]TET-Tetris Attack
洛谷题目链接:[POI2007]TET-Tetris Attack 题目描述 A puzzle called "Tetris Attack" has lately become a ...
- [洛谷3457][POI2007]POW-The Flood
洛谷题目链接:[POI2007]POW-The Flood 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方 ...
- 洛谷P3459 [POI2007]MEG-Megalopolis(树链剖分,Splay)
洛谷题目传送门 正解是树状数组维护dfn序上的前缀和,这样的思路真是又玄学又令我惊叹( 我太弱啦,根本想不到)Orz各路Dalao 今天考了这道题,数据范围还比洛谷的小,只有\(10^5\)(害我复制 ...
- 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]
题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...
- 洛谷 P3456 [POI2007]GRZ-Ridges and Valleys
P3456 [POI2007]GRZ-Ridges and Valleys 题意翻译 给定一个地图,为小朋友想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的.若两 ...
- 洛谷 P3455 [POI2007]ZAP-Queries (莫比乌斯函数)
题目链接:P3455 [POI2007]ZAP-Queries 题意 给定 \(a,b,d\),求 \(\sum_{x=1}^{a} \sum_{y=1}^{b}[gcd(x, y) = d]\). ...
- 洛谷P3459 [POI2007]MEG-Megalopolis [2017年6月计划 树上问题02]
[POI2007]MEG-Megalopolis 题目描述 Byteotia has been eventually touched by globalisation, and so has Byte ...
- 【刷题】洛谷 P3455 [POI2007]ZAP-Queries
题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...
- 洛谷P3457 [POI2007]POW-The Flood [并查集,模拟]
题目传送门 pow 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方形,地图上已经标注了它的海拔高度以及它是 ...
随机推荐
- HDU4565 So Easy! —— 共轭构造、二阶递推数列、矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4565 So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- java random配置修改
不知道 报啥错的时候 ,改这个 vim /usr/java/latest/jre/lib/security/java.security 原值: securerandom.source=file:/de ...
- 在一个form表单中根据不同按钮实现多个action事件
<form id="writeForm" method="post"> <div class="write-btn-tj" ...
- margin-top 为什么会影响父元素的 margin-top
1.原因: In this specification, the expression collapsing margins means that adjoining margins (no non ...
- linux下mycat读写分离的配置
为什么要配置读写分离,我想我就不需要再赘述了,那么在mycat下如何进行读写分离的配置,配置之后的实际效率又如何呢?我上午根据文档捣鼓和测试了一下,这里做一下记录: 最开始,我们还是要配置mysql本 ...
- hdu-4989 Summary(水题)
题目链接: Summary Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) P ...
- IO多路复用模型之epoll实现机制
设想一下如下场景:有100万个客户端同时与一个服务器进程保持着TCP连接.而每一时刻,通常只有几百上千个TCP连接是活跃的(事实上大部分场景都是这种情况).如何实现这样的高并发? 在select/po ...
- Azure AD (5) 在单一目录下,使用Azure AD单点登录
<Windows Azure Platform 系列文章目录> 本文介绍的是,在单一目录下,使用Azure AD Connect,打通本地Domain Controller 我们需要准备的 ...
- CentOS 6.5远程连接工具x shell
安装X shell 在Window系统下远程连接Linux,x shell只是一种远程连接工具,类似工具还有CRT.VNC.putty. 以下是安装X shell的注意事项 此选项中,如不把——初始数 ...
- Android开发--Activity
一:Activity生命周期 (1)Activity生命周期中的几种方法: protected void onCreate(Bundle savedInstanceState): protected ...