题面:

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. 【 spring配置文件详解】

    转自: http://book.51cto.com/art/201004/193743.htm Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的 ...

  2. HDU4850 Wow! Such String! —— 字符串构造

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4850 代码如下: #include <iostream> #include <cst ...

  3. system调用命令行命令而不显示命令行窗口

    system调用命令行命令而不显示命令行窗口 通常用system调用命令行命令时都会弹出黑底白字的命令行窗口,下面的代码可以不显示弹出的命令行窗口. 代码如下 #pragma comment( lin ...

  4. python把字典写入excel之一例

    直接上代码: # -*- coding: utf-8 -*- import xlsxwriter #生成excel文件 def generate_excel(expenses): workbook = ...

  5. android BLE Peripheral 手机模拟设备发出BLE广播 BluetoothLeAdvertiser

    android 从4.3系统开始可以连接BLE设备,这个大家都知道了.iOS是从7.0版本开始支持BLE. android 进入5.0时代时,开放了一个新功能,手机可以模拟设备发出BLE广播, 这个新 ...

  6. gzhu 2013 Good Sequence 解题报告

    题目链接:(这个是内网的网址)  http://172.22.27.1/problem?pid=1013 Good Sequence Time Limit: 4000/2000 MS (Java/Ot ...

  7. TCPDUMP 使用详情

    第一种是关于类型的关键字,主要包括host,net,port, 例如 host 210.27.48.2,指明 210.27.48.2是一台主机,net 202.0.0.0 指明 202.0.0.0是一 ...

  8. Can't locate Log/Dispatch.pm in @INC

    记录一下配置mha的时候遇到的错误,使用perl模块发送邮件的时候报以下错误: # masterha_check_ssh --conf=/data/mha/app1.cnf Can't locate ...

  9. 激活层和pooling的作用

    激活层: 激活函数其中一个重要的作用是加入非线性因素的,将特征映射到高维的非线性区间进行解释,解决线性模型所不能解决的问题 pooling层: 1. invariance(不变性),这种不变性包括tr ...

  10. c++11 右值引用和移动语义

    什么是左值.右值 最常见的误解: 等号左边的就是左值,等号右边的就是右值 左值和右值都是针对表达式而言的, 左值是指表达式结束后依然存在的持久对象 右值是指表达式结束时就不再存在的临时对象区分: 能对 ...