Codeforces Round #350 (Div. 2) D2 二分
五一期间和然然打的团队赛..那时候用然然的号打一场掉一场...七出四..D1是个数据规模较小的题 写了一个暴力过了 面对数据如此大的D2无可奈何 现在回来看 一下子就知道解法了
二分就可以 二分能做多少个 每次对mid求一下不够的差值 比较差值与m的大小进行l与r的变换
由于自己一向对二分比较迷茫 自己琢磨出来一套神奇的办法面对边界数据
当小于和大于的时候 抛弃mid值
当等于的时候 直接break 然后打一发while试试能否向更好的情况偏移
当然在这个题目中 如果是直接break的时候就不用偏移了
使用了llu 如果lld的话貌似会挂的样子
如果没有直接break出来的情况 最后l r mid 之间的差值一定就是1和0 那么l-5一定是小于三者的..
llu小于0会直接转化为极大的值 所以需要if判断一下
该去学习一下二分的姿势了...
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<iostream>
#include<vector>
#include<string>
#include<set>
using namespace std;
unsigned long long int n,m;
unsigned long long int a[100050];
unsigned long long int b[100050];
int main()
{
cin>>n>>m;
for(int i = 1; i<=n; i++)
{
scanf("%llu",&a[i]);
}
for(int i = 1; i<=n; i++)
{
scanf("%llu",&b[i]);
}
unsigned long long int l = 0;
unsigned long long int r = 3e9;
unsigned long long mid;
while(l<r)
{
mid=(l+r)/2;
unsigned long long cz=0;
for(int i = 1; i<=n; i++)
{
unsigned long long aa= a[i]*mid;
if(b[i]<aa)
{
cz+=(aa-b[i]);
}
}
if(cz>m)
{
r=mid-1;
}
else if(cz<m)
{
l=mid+1;
}
else break;
}
unsigned long long cz=0;
for(int i = 1; i<=n; i++)
{
unsigned long long aa= a[i]*mid;
if(b[i]<aa)
{
cz+=(aa-b[i]);
}
}
if(cz==m)
{
printf("%llu\n",mid);
return 0;
}
unsigned long long int z;
if(mid<5)
z=0;
else
z=mid-5;
while(true)
{
z++;
unsigned long long x=0;
for(int i=1; i<=n; i++)
{
unsigned long long aa= a[i]*z;
if(b[i]<aa)
{
x+=(aa-b[i]);
}
}
if(x>m)
break;
}
printf("%llu\n",z-1);
}
Codeforces Round #350 (Div. 2) D2 二分的更多相关文章
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...
- Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】
A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ...
- 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 Round #540 (Div. 3) D2. Coffee and Coursework (Hard Version) (二分,贪心)
题意:有\(n\)个数,每次可以选\(k(1\le k\le n)\)个数,并且得到\(a_1+max(0,a_2-1)+max(0,a_3-2)+...+max(0,a_k-k+1)\)的贡献,问最 ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- 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 ...
随机推荐
- css3 -- 伪类与伪元素
伪类: 1.结构伪类 A:E : first-child{} E : nth-*(n){} E : first-*(even){} E : first-*(odd){} B:nth-child 是根 ...
- Codeforces 543D Road Improvement(树形DP + 乘法逆元)
题目大概说给一棵树,树的边一开始都是损坏的,要修复一些边,修复完后要满足各个点到根的路径上最多只有一条坏的边,现在以各个点为根分别求出修复边的方案数,其结果模1000000007. 不难联想到这题和H ...
- BZOJ2597 [Wc2007]剪刀石头布(最小费用最大流)
题目大概是说n个人两两进行比赛,问如何安排几场比赛的输赢使得A胜B,B胜C,C胜A这种剪刀石头布的三元组最多. 这题好神. 首先,三元组总共有$C_n^3$个 然后考虑最小化不满足剪刀石头布条件的三元 ...
- HIT2543 Stone IV(一定费用内的最大流)
题目大概说,有n个从0到n-1的城市,要从城市0运送石头到城市1,运送石头的单价是p.城市间的有m条双向路相连,路都有能运送石头的限额c1,如果超过限额运送石头的单价就要提高c2.问在总花费c以内能运 ...
- Python: 常用list, string处理功能
#1. keep strings in double quote as one word when split string to words #e.g. str = ‘a b "is si ...
- 优先使用最新版本的IE 和 Chrome 内核 1 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
兼容模式 优先使用最新版本的IE 和 Chrome 内核 1 <meta http-equiv="X-UA-Compatible" content="IE=edge ...
- Sphinx 全量索引加实时索引
source mysql { type = mysql sql_host = 10.10.3.181 sql_user = root sql_pass = dsideal sql_db = dside ...
- WZJ的blog开通了
WZJ的blog开通了
- iOS 网络框架编写总结
一,常用 1> 不错的处理接收到的网络图片数据的方法 id img= ISNSNULL(pic)?nil:[pic valueForKey:@"img"]; NSString ...
- LBS基站数据解析接口
http://www.cellocation.com/interfac/#hybrid http://www.cellid.cn/ https://www.juhe.cn/docs/api/id/8