题面:

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. CORS 理解(不要那么多术语)

    摘要 谈到跨域,不论前端还是后端,多少有点谈虎色变,面试中也常会问到这些问题,浏览器和服务器端到底怎么做才能跨域,他们都做了什么? 同源 vs 跨域 同源,字面意义是相同的源头,即同一个web服务器( ...

  2. Ubuntu下声卡驱动解决方法alsa

    一.首先介绍一下什么是ALSA : Advanced Linux Sound Architecture 的简称为 ALSA ,译成中文的意思是先进的Linux声音架构(这是google翻译的):一谈到 ...

  3. 第三篇:python基础之数据类型与变量

    阅读目录 一.变量 二.数据类型 2.1 什么是数据类型及数据类型分类 2.2 标准数据类型: 2.2.1 数字 2.2.1.1 整型: 2.2.1.2 长整型long: 2.2.1.3 布尔bool ...

  4. Duplicate files copied in APK META-INF/DEPENDENCIES

    在app的目录下找到build.gradle 这个文件,在android标签的最后面加入以下信息: packagingOptions { exclude 'META-INF/DEPENDENCIES' ...

  5. requireJS 加载css、less文件

    -- requireJS 同样可以加载css 文件,有require-css的插件,只需要把插件放入main.js同文件夹,在依赖处 采用 ‘css! test.css’的形式就可以加载css文件 - ...

  6. 用python做自动化测试--Python实现远程性能监控

    http://blog.csdn.net/powerccna/article/details/8044222 在性能测试中,监控被测试服务器的性能指标是个重要的工作,包括CPU/Memory/IO/N ...

  7. kali本機安裝openvas的血淚史復盤

    安裝openvas的血淚史 因爲學習的需要,需要裝openvas,但是在虛擬機裏面,無論怎麼更新跟新源,總是會有問題,一氣之下,便不用虛擬機了,將自己的物理機刷成了kali機,從此便進了一個大坑. 安 ...

  8. bzoj 3771 Triple —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3771 令多项式的系数是方案数,次数是值: 设 a(x) 为一个物品的多项式,即 a[w[i] ...

  9. zynq交叉编译环境设置

    环境准备 Vmware 虚拟机:ubuntu14.04 下载安装文件 环境设置 按照上面地址下载 xilinx-2011.09-50-arm-xilinx-linux-gnueabi.bin 将das ...

  10. javascript 前段MVVM 框架

    http://www.likebin.net/meteorlist.html http://www.cnblogs.com/sskyy/p/3197917.html