题面:

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

  1. [洛谷P3460] [POI2007]TET-Tetris Attack

    洛谷题目链接:[POI2007]TET-Tetris Attack 题目描述 A puzzle called "Tetris Attack" has lately become a ...

  2. [洛谷3457][POI2007]POW-The Flood

    洛谷题目链接:[POI2007]POW-The Flood 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方 ...

  3. 洛谷P3459 [POI2007]MEG-Megalopolis(树链剖分,Splay)

    洛谷题目传送门 正解是树状数组维护dfn序上的前缀和,这样的思路真是又玄学又令我惊叹( 我太弱啦,根本想不到)Orz各路Dalao 今天考了这道题,数据范围还比洛谷的小,只有\(10^5\)(害我复制 ...

  4. 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]

    题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...

  5. 洛谷 P3456 [POI2007]GRZ-Ridges and Valleys

    P3456 [POI2007]GRZ-Ridges and Valleys 题意翻译 给定一个地图,为小朋友想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的.若两 ...

  6. 洛谷 P3455 [POI2007]ZAP-Queries (莫比乌斯函数)

    题目链接:P3455 [POI2007]ZAP-Queries 题意 给定 \(a,b,d\),求 \(\sum_{x=1}^{a} \sum_{y=1}^{b}[gcd(x, y) = d]\). ...

  7. 洛谷P3459 [POI2007]MEG-Megalopolis [2017年6月计划 树上问题02]

    [POI2007]MEG-Megalopolis 题目描述 Byteotia has been eventually touched by globalisation, and so has Byte ...

  8. 【刷题】洛谷 P3455 [POI2007]ZAP-Queries

    题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...

  9. 洛谷P3457 [POI2007]POW-The Flood [并查集,模拟]

    题目传送门 pow 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方形,地图上已经标注了它的海拔高度以及它是 ...

随机推荐

  1. 怎样使用alsa API

    翻译文章的链接: http://equalarea.com/paul/alsa-audio.html 关于怎么使用ALSA API教程 这份文档帮助对ALSA API使用入门.不是一个完整的ALSA ...

  2. Appium——adb 启动问题Invalid argument: cannot open transport registration socketpair could not read ok from ADB Server failed to start daemon * error: cannot connect to daemon

    adb启动问题:Invalid argument: cannot open transport registration socketpair could not read ok from ADB S ...

  3. 动态负载均衡(Nginx+Consul+UpSync)环境搭建

    首先 安装好 Consul upsync 然后: 1.配置安装Nginx 需要做配置,包括分组之类的,创建目录,有些插件是需要存放在这些目录的 groupadd nginx useradd -g ng ...

  4. PHP截取中英文混合字符

    <?php //////////////////////////////////////////////////////////////////// // PHP截取中英文及标点符号混合的字符串 ...

  5. Swing项目编译成exe,并且打包成安装文件(一)

    我们一般用java做Swing项目的时候一般都是只能在Myeclipse里面运行,那么怎么把我们的项目打包成exe可以直接双击运行呢? 初始工作:为了不让用户安装java环境,所以我们先新建一个文件夹 ...

  6. pycharm 开发连接linux 服务器

    这样就可以了.....

  7. python 基础之第五天

    ###########window路径写法########## In [1]: winpath = 'C:\tmp' In [2]: print winpath C: mp In [3]: winpa ...

  8. C++之remove和remove_if

    一.Remove()函数 remove(beg,end,const T& value) //移除区间{beg,end)中每一个“与value相等”的元素: remove只是通过迭代器的指针向前 ...

  9. JAVA 中的堆和栈

    栈与堆都是Java用来在Ram中存放数据的地方.与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆.     Java的堆是一个运行时数据区,类的对象从中分配空间.这些对象通过new.n ...

  10. 24.如何结束返回值是void的方法

    如何结束返回值是void的方法? return;只能够出现在方法类型是void 的方法中,用来结束方法. return后面还可以跟数据,后面的数据可以是整数.字符串.false.ture.小数.主要看 ...