洛谷 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的小正方形.对于每个小正方形,地图上已经标注了它的海拔高度以及它是 ...
随机推荐
- Promise 源码分析
前言 then/promise项目是基于Promises/A+标准实现的Promise库,从这个项目当中,我们来看Promise的原理是什么,它是如何做到的,从而更加熟悉Promise 分析 从ind ...
- 绝对定位(absolute)
绝对定位(absolute),作用是将被赋予此定位方法的对象从文档流中拖出,使用left,right,top, bottom等属性相对于其最接近的一个最有定位设置的父级对象进行绝对定位,如果对象的父级 ...
- Kattis - whatdoesthefoxsay —— 字符串
题目: Kattis - whatdoesthefoxsay Determined to discover the ancient mystery—the sound that the fox ...
- java版的下雪,大家圣诞快乐
1. [代码][Java]代码 package com.yk.tools.game; import java.applet.AudioClip;import java.awt.Dimension ...
- Linux_基于Docker快速搭建个人博客网站
时间:2017年04月28日星期五 说明:基于docker技术,使用jpress开源框架搭建个人博客网站.特别感谢jpress开源项目.系统版本:CentOS 7.2-64bit. 步骤一:准备Doc ...
- Grunt 自动编译 Less 文件配置
1.安装Grunt http://www.gruntjs.net/getting-started 2.编辑 package.json 文件 { "name": "Grun ...
- Tensorflow和Caffe 简介
TensorFlow TensorFlow 是相对高阶的机器学习库,用户可以方便地用它设计神经网络结构,而不必为了追求高效率的实现亲自写 C++或 CUDA 代码.它和 Theano 一样都支持自动求 ...
- 快速沃尔什变换(FWT)学习笔记 + 洛谷P4717 [模板]
FWT求解的是一类问题:\( a[i] = \sum\limits_{j\bigoplus k=i}^{} b[j]*c[k] \) 其中,\( \bigoplus \) 可以是 or,and,xor ...
- Docker运行MongoDB及Redis及ssh端口映射远程连接
Docker运行MongoDB及Redis及ssh端口映射远程连接 本节内容简介 在本实验里我们将通过完成 MongoDB 和 Redis 两个容器来学习Dockerfile及Docker的运行机制. ...
- 深入Mybatis配置文件
Configuration是干嘛的 Configuration就像是Mybatis的总管,Mybatis的所有配置信息都存放在这里,此外,它还提供了设置这些配置信息的方法.Configuration可 ...