题意:今天我们要来造房子。造这个房子需要n种原料,每造一个房子需要第i种原料ai个。现在你有第i种原料bi个。此外,你还有一种特殊的原料k个,

每个特殊原料可以当作任意一个其它原料使用。那么问题来了,你最多可以造多少个房子呢?

析:首先可以先把开始能造出的先处理出来,然后再进行二分,当然也可以直接进行二分。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int a[maxn], b[maxn]; bool judge(LL mid){
LL mm = m;
for(int i = 0; i < n; ++i){
if(b[i] / a[i] >= mid) continue;
mm += b[i] - a[i] * mid;
if(mm < 0) return false;
}
return true;
} int main(){
scanf("%d %d", &n, &m);
LL sum = 0;
for(int i = 0; i < n; ++i){
scanf("%d", a+i);
sum += a[i];
}
int ans = INF;
for(int i = 0; i < n; ++i){
scanf("%d", b+i);
ans = min(ans, b[i] / a[i]);
}
for(int i = 0; i < n; ++i) b[i] -= a[i] * ans; LL l = 0, r = m;
while(l < r){
int mid = l + (r-l+1) / 2;
if(judge(mid)) l = mid;
else r = mid - 1;
}
cout << ans + l << endl;
return 0;
}

  

CodeForces 670D2 Magic Powder - 2 (二分)的更多相关文章

  1. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  2. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  3. codeforces 350 div2 D Magic Powder - 2 二分

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codefroces D2. Magic Powder - 2(二分)

    http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...

  5. Codeforces 670D1. Magic Powder - 1 暴力

    D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...

  6. CodeForces 670D Magic Powder

    二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...

  7. Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. D2 Magic Powder -1/- 2---cf#350D2(二分)

    题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...

  9. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

随机推荐

  1. ACM学习历程—Hihocoder 1291 Building in Sandbox(dfs && 离线 && 并查集)

    http://hihocoder.com/problemset/problem/1291 前几天比较忙,这次来补一下微软笔试的最后一题,这题是这次微软笔试的第四题,过的人比较少,我当时在调试B题,没时 ...

  2. python模型字段

    http://python.usyiyi.cn/translate/django_182/ref/models/fields.html#model-field-types

  3. MeshBaker

    https://blog.csdn.net/z9895512/article/details/52297387 详细教程直接贴一个其他人写的教程,这个人写得很详细,插件的各种功能几乎都有教程: htt ...

  4. jquery.tmpl的使用

    jquery.tmpl是jQuery模板插件,http://plugins.jquery.com/tmpl/ (另外还有一个插件dot.js,不依赖与jquery,性能更佳,使用方法大同小异) 在网页 ...

  5. CF 19E Fairy——树上差分

    题目:http://codeforces.com/contest/19/problem/E 去掉一条边,使无向图变成二分图. 该边应该被所有奇环经过,且不被偶环经过. 因为一条非树边一定只在一个环里. ...

  6. c++11之三: sizeof运算符 auto的优势 __func__预定义标识符

    在C++11中,对非静态成员变量使用sizeof操作是合法的. auto推导的一个最大优势就是在拥有初始化表达式的复杂类型变量声明时简化代码.如:std:vector<std::string&g ...

  7. check: 获得所有呗选中的checked标签的元素值 mapArrayElement(arrEles)

    首先引用: <script src="../js/myjs/mapArrayElement.js"></script> 然后在<javascript& ...

  8. final,finally和finalize三者的区别和联系

    对于初学者而言(当然也包括我)对于这三者真的不是很陌生,经常会看到它们.但对于三者之间的区别和联系一直是懵懵懂~~ 今天心情不错,那就简单总结一下它们几个的区别和联系吧.如果又不对的地方欢迎批评指正~ ...

  9. TCG卡牌游戏研究:《炉石战记:魔兽英雄传》所做的改变

    转自:http://www.gameres.com/665306.html TCG演进史 说到卡牌游戏,大家会联想到什么呢? 是历史悠久的扑克牌.风靡全球的<MTG 魔法风云会>与< ...

  10. maven学习6 Eclipse下Tomcat常用设置

    Eclipse下Tomcat常用设置 1,Eclipse建立Tomcat服务 1.1 新建Server 首先这里是指,jee版的Eclipse.Eclipse是没有像MyEclipse那样集成Tomc ...