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 ...
随机推荐
- 如何用nodejs启一个前端服务
1.新建文件夹,如 notice 2.新建页面和js文件,如 index.html server.js 3.index.html页面内容随你写,如: <!DOCTYPE html> < ...
- 纯css 更改原生raiod与 checkbox的样式
原文地址: .checkbox input[type=checkbox], .checkbox-inline input[type=checkbox], .radio input[type=radio ...
- Installing Redis more properly
Installing Redis more properly Running Redis from the command line is fine just to hack a bit with i ...
- EMIPLIB简介
EMIPLIB(http://research.edm.uhasselt.be/emiplib)的全称是'EDM Media over IP libray' .EDM是Hasselt Universi ...
- 2018年长沙理工大学第十三届程序设计竞赛 E小木乃伊到我家(spfa模版)
链接:https://www.nowcoder.com/acm/contest/96/E来源:牛客网 小木乃伊到我家 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他 ...
- Eclipse中的普通Java项目如何部署到Tomcat中
我现在的做法: 1.在Eclipse中配置Tomcat时,选择创建Context文件,而不是server.xml,好处是文件可以随便命名,与虚拟目录一致(即xml中的属性path).Tomcat加载项 ...
- windows下socket编程:区分shutdown()及closesocket()
以下描述主要是针对windows平台下的TCP socket而言. 首先需要区分一下关闭socket和关闭TCP连接的区别,关闭TCP连接是指TCP协议层的东西,就是两个TCP端之间交换了一些协议包( ...
- Delphi Cookie
Cookie IdHTTP1.CookieManager.AddCookies(); IdHTTP1.Post(); IdHTTP1.Get('http://1.1.1.1:9000/'); for ...
- scrapy(1)安装
用的是python3.6 pip install -i https://pypi.douban.com/simple/ scrapy scrapy startproject Article scrap ...
- Spring事务SPI及配置介绍
Spring事务SPI及配置介绍 标签: spring事务aop数据管理 2015-05-17 11:42 606人阅读 评论(0) 收藏 举报 分类: Spring(12) 版权声明:本文为 ...