五一期间和然然打的团队赛..那时候用然然的号打一场掉一场...七出四..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 二分的更多相关文章

  1. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  2. 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) ...

  3. 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 ...

  4. Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】

    A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ...

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

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

  6. 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)\)的贡献,问最 ...

  7. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  8. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  9. 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 ...

随机推荐

  1. css3 -- 多列

    1.指定分列: E{column-count:2:} --- 两列 E{ -moz-column-count:2: -webkit-column-count:2: } Firefox与webkit实现 ...

  2. HDU3395 Special Fish(最大费用任意流)

    题目要的并不是最大匹配下得到的最大的结果. 网上流行的做法是加边.其实,在连续增广的时候求得一个可行流的总费用为负就停止这样就行了. #include<cstdio> #include&l ...

  3. iOS开发代码规范(通用)

    1. 关于命名 1> 统一要求 含义清楚,尽量做到不需要注释也能了解其作用,若做不到,就加注释 使用全称,不适用缩写 2> 类的命名 大驼峰式命名:每个单词的首字母都采用大写字母 例子:M ...

  4. iOS之05-三大特性之封装

    本次主要学习面向对象的三大特性:封装.继承和多态中的封装 封装 1. 好处 降低耦合率 可重复调用类中的属性 提高安全性,外部不能随便修改变量的值,保证了数据的安全性 2. set方法 1.作用:提供 ...

  5. storm 原理简介及单机版安装指南——详细版【转】

    storm 原理简介及单机版安装指南 本文翻译自: https://github.com/nathanmarz/storm/wiki/Tutorial 原文链接自:http://www.open-op ...

  6. CSS样式覆盖顺序

    有时候在写CSS的过程中,某些限制总是不起作用,这就涉及了CSS样式覆盖的问题,如下 Css代码   #navigator { height: 100%; width: 200; position:  ...

  7. Issues I encountered when building Windows Store apps on a new laptop

    I took over my beloved wives samsung ativ book 9 recently as her first job granted her a brandnew su ...

  8. Linux远程传输命令之scp使用方法

      首先用pwd命令确定文件全路径   1.获取远程服务器上的文件 cykdeMacBook-Pro:~ cyk$ scp cyk@10.211.55.5:/home/cyk/Desktop/hi.t ...

  9. SRM 594 DIV1 250

    可能开始宿舍比较乱,思绪静不下来...想了大半个小时,终于确定了应该暴力+DP,然后写了枚举除数,和被除的版本..这样,还敲错了个字母,第一次提交还100多,修改提交还有75.多,最后想到,貌似不打对 ...

  10. 获取UILabel宽度的方法

    - (CGFloat)labelLength:(NSString *)str font:(CGFloat)font{ str = ISSTRING(str) ? str : @"" ...