CodeForces 670D2 Magic Powder - 2 (二分)
题意:今天我们要来造房子。造这个房子需要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 (二分)的更多相关文章
- CodeForces 670D2 Magic Powder 二分
		
D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...
 - Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
		
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
 - 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 ...
 - Codefroces  D2. Magic Powder - 2(二分)
		
http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...
 - Codeforces 670D1. Magic Powder - 1 暴力
		
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...
 - CodeForces 670D Magic Powder
		
二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...
 - 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 ...
 - D2 Magic Powder -1/- 2---cf#350D2(二分)
		
题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...
 - Magic Powder - 2 (CF  670_D)
		
http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...
 
随机推荐
- 【phpcms-v9】前台content模块中pc标签的调用说明
			
内容模块PC标签调用说明 模块名:content 模块提供的可用操作 操作名 说明 lists 内容数据列表 relation 内容相关文章 hits 内容数据点击排行榜 category 内容栏目列 ...
 - Linux命令学习(20):traceroute命令
			
版权声明 更新:2017-06-13博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下面的mv命令. 2 ...
 - npm镜像安装
			
安装淘宝NPM镜像 https://npm.taobao.org/ npm install -g cnpm --registry=https://registry.npm.taobao.org 配置 ...
 - Django基础(三)
			
Template 不能直接将html硬编码到视图里的原因: 对页面设计进行的任何改变都必须对python 代码进行相应的修改.站点设计的修改往往比底层python 代码的修改要频繁的多,因此如果可以在 ...
 - HTTP-Runoob:HTTP状态码
			
ylbtech-HTTP-Runoob:HTTP状态码 1.返回顶部 1. HTTP状态码 当浏览者访问一个网页时,浏览者的浏览器会向网页所在服务器发出请求.当浏览器接收并显示网页前,此网页所在的服务 ...
 - spring boot 学习10  定义springboot的两种方法
			
使用spring boot的两种方法: A:继承spring-boot-starter-parent项目 这种方式很简单,只需要在POM里面添加parent父工程即可. B: 如果你不喜欢继承spri ...
 - PowerDesigner的Additional Checkes 中使用统配符
			
在Domian或字段的的约束条件中,会用的正则表达式等约束.但正则表达式 regexp_like(ICAO,'^([A-Z]{4}$')中要出现明确字段名如ICAO,每个使用同样约束的字段都要修改此字 ...
 - PHP实现常用排序算法(含示意动图)
			
目录 1 快速排序 2 冒泡排序 3 插入排序 4 选择排序 5 归并排序 6 堆排序 7 希尔排序 8 基数排序 总结 作为phper,一般接触算法的编程不多. 但基本的排序算法还是应该掌握. 毕竟 ...
 - equals()与hashCode()方法详解
			
java.lang.Object类中有两个非常重要的方法: 1 2 public boolean equals(Object obj) public int hashCode() Object类是类继 ...
 - matlab图片高清复制到visio
			
编辑→复制图窗→在visio中粘贴