五一期间和然然打的团队赛..那时候用然然的号打一场掉一场...七出四..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. Scau 8633 回文划分 mancher + dp

    时间限制:1000MS 内存限制:1000K 提交次数: 通过次数: 题型: 编程题 语言: G++;GCC Description 我们说一个字符串是回文串,那么意味着这个串从两边读起来的字母都是一 ...

  2. The 13th Zhejiang Provincial Collegiate Contest(2016年浙江省赛)

      前4道水题就不说了,其中我做了C题,1Y,小心仔细写代码并且提交之前得确认无误后提交才能减少出错率. 结果后面2题都由波神做掉,学长带我们飞~ 终榜 官方题解   ZOJ 3946 Highway ...

  3. Android 自动化测试—robotium(六) 通过命令行执行Robotium自动化测试用例及导出报告

    1.运行测试工程下的所有用例 adb shell am instrument -w com.application.test/android.test.InstrumentationTestRunne ...

  4. Mvc网站发布到IIS

    网站发布步骤: 这部分是转载文章 在此标明出处,以前有文章是转的没标明的请谅解,因为有些已经无法找到出处,或者与其它原因. 如有冒犯请联系本人,或删除,或标明出处. 因为好的文章,以前只想收藏,但连接 ...

  5. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  6. hadoop2.2.0 + hbase 0.94 + hive 0.12 配置记录

    一开始用hadoop2.2.0 + hbase 0.96 + hive 0.12 ,基本全部都配好了.只有在hive中查询hbase的表出错.以直报如下错误: java.io.IOException: ...

  7. POJ 3276 (开关问题)

    题目链接: http://poj.org/problem?id=3276 题目大意:有一些牛,头要么朝前要么朝后,现在要求确定一个连续反转牛头的区间K,使得所有牛都朝前,且反转次数m尽可能小. 解题思 ...

  8. background常用属性

    background-image:url('图片位置');//设置背景图片的位置 background-repeat:no-repeat;//图片是否重复显示(不重复) background-posi ...

  9. hdu1232 并查集

    1. hdu1232 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 3.总结:简单并查集 #include<iostream> # ...

  10. Idea_Intellij Idea 12 生成serialVersionUID的方法

    默认情况下Intellij IDEA是关闭了继承了java.io.Serializable的类生成serialVersionUID的警告.如果需要ide提示生成serialVersionUID,那么需 ...