这个题。。。只能说比较水。。。

排序后,算一个前缀和,二分dfs查找答案。。。加上两个剪枝就过了。。。QVQ

我只能刷这种水题。。。我太菜了。。。QVQ

#include<iostream>
#include<cstdio>
#include<algorithm>
#define maxn 100010
using namespace std; int a[maxn],b[maxn],c[maxn];
int n,m,ans,tot,waste,mid; inline bool check(int x,int st)
{
if(waste>tot-c[mid]) return ;
if(x==) return ;
for(int i=st;i<=m;i++)
if(a[i]>=b[x])
{
bool flag=;
a[i]-=b[x];
if(a[i]<b[]) waste+=a[i];
if(b[x-]==b[x])
flag=check(x-,i);
else flag=check(x-,);
if(a[i]<b[]) waste-=a[i];
a[i]+=b[x];
if(flag==) return ;
}
return ;
} int main()
{
scanf("%d",&m);
for(int i=;i<=m;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++) tot+=a[i];
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
sort(a+,a++m); sort(b+,b++n);
for(int i=;i<=n;i++) c[i]=c[i-]+b[i];
while(c[n]>tot) n--;
int l=,r=n;
while(l<=r)
{
int mid=l+r>>;
if(check(mid,))
ans=mid,l=mid+;
else r=mid-;
}
printf("%d\n",ans);
}

呆码

[SCOI2005]栅栏的更多相关文章

  1. 【BZOJ1082】[SCOI2005]栅栏(搜索)

    [BZOJ1082][SCOI2005]栅栏(搜索) 题面 BZOJ 洛谷 题解 随便写个爆搜,洛谷上就\(80\)分了.先放爆搜代码: #include<iostream> #inclu ...

  2. 洛谷 P2329 [SCOI2005]栅栏 解题报告

    P2329 [SCOI2005]栅栏 题目描述 农夫约翰打算建立一个栅栏将他的牧场给围起来,因此他需要一些特定规格的木材.于是农夫约翰到木材店购买木材.可是木材店老板说他这里只剩下少部分大规格的木板了 ...

  3. [BZOJ1082][SCOI2005]栅栏 二分+搜索减枝

    1082: [SCOI2005]栅栏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2430  Solved: 1034[Submit][Status ...

  4. bzoj1082: [SCOI2005]栅栏(二分答案搜索判断)

    1082: [SCOI2005]栅栏 题目:传送门 题解: 是不是一开始在想DP?本蒟蒻也是qwq,结果很nice的错了ORZ 正解:二分+搜索 我们可以先把两种木材都进行排序,那么如果需要的最大木材 ...

  5. bzoj 1082: [SCOI2005]栅栏 题解

    1082: [SCOI2005]栅栏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 991[Submit][Status] ...

  6. SCOI2005栅栏

    Description 农夫约翰打算建立一个栅栏将他的牧场给围起来,因此他需要一些特定规格的木材.于是农夫约翰到木材店购买木材.可是木材店老板说他这里只剩下少部分大规格的木板了.不过约翰可以购买这些木 ...

  7. bzoj1082[SCOI2005]栅栏

    Description 农夫约翰打算建立一个栅栏将他的牧场给围起来,因此他需要一些特定规格的木材.于是农夫约翰到木材店购 买木材.可是木材店老板说他这里只剩下少部分大规格的木板了.不过约翰可以购买这些 ...

  8. bzoj 1082: [SCOI2005]栅栏

    Description 农夫约翰打算建立一个栅栏将他的牧场给围起来,因此他需要一些特定规格的木材.于是农夫约翰到木材店购 买木材.可是木材店老板说他这里只剩下少部分大规格的木板了.不过约翰可以购买这些 ...

  9. 【bzoj1082】 SCOI2005—栅栏

    http://www.lydsy.com/JudgeOnline/problem.php?id=1082 (题目链接) 题意 给出m块木柴,以及n块木板,要求将m块木柴做木板,要求将木柴切割成与木板一 ...

  10. BZOJ1082: [SCOI2005]栅栏 题解

    题目大意: 有一些木材,可以没有浪费地将一根木材分成几块木板(比如长度为10的木板可以切成长度为8和2的两块木板).现在你希望得到一些长度的木板,问通过分割木材最多能得到几块想要的木板. 思路: 首先 ...

随机推荐

  1. English trip V1 - B 15. Giving Personal Information 提供个人信息 Teacher:Solo Key: Do/Does

    In this lesson you will learn to answer simple questions about yourself.  本节课讲学到回答关于自己的一些简单问题 课上内容(L ...

  2. Lua常用封装方法

    Lua 获取随机值 --获取随机值,指定上限和下限 function getRandom(min,max) -- 接收一个整数n作为随即序列的种子 math.randomseed(os.time()) ...

  3. vue 点击一个div,使input获得焦点

    <div class="inputMessage" @click="inputMessage">输入留言</div> <input ...

  4. python基础之生成器,生成器函数,列表推导式

    内容梗概: 1. 生成器和生成器函数. 2. 列表推导式. 1.生成器函数1.1 生成器函数. 就是把return换成yield def gen(): print("爽歪歪") y ...

  5. 384. Shuffle an Array(java,数组全排列,然后随机取)

    题目: Shuffle a set of numbers without duplicates. 分析: 对一组不包含重复元素的数组进行随机重排,reset方法返回最原始的数组,shuffle方法随机 ...

  6. Remove Element leetcode java

    问题描述: Given an array and a value, remove all instances of that value in place and return the new len ...

  7. Python安装第三方库,报错超时: Read timed out.

    1.安装beautifulsoup4 >pip install beautifulsoup4 报错超时: Read timed out. 2.解决办法:pip --default-timeout ...

  8. 11204RAC-dbca建库脚本

    SET VERIFY OFFconnect "SYS"/"&&sysPassword" as SYSDBAset echo onspool /u ...

  9. bootstrap居中

    1.页面 <div class="container"> <div class="row clearfix"> <div clas ...

  10. JQuary中的FullPage属性的用法

    $(document).ready(function(){ //常用方法    //$.fn.fullpage.moveSectionUp()   //向上滚动一页 //$.fn.fullpage.m ...