五一期间和然然打的团队赛..那时候用然然的号打一场掉一场...七出四..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. python安装setuptools

    http://wenku.baidu.com/link?url=I-FCVFpHbP2oyCt1Gjb1X5xHk4P475dVU3j8rWd4b4VSuD-Wd86LdbC7bdYskZdtDfGK ...

  2. 编写unit test以及自动化测试WebDriver

    http://msdn.microsoft.com/en-us/library/hh694602.aspx#BKMK_Quick_starts   http://www.seleniumhq.org/ ...

  3. Activiti工作流学习(一)部署对象和流程定义

    一.前言 前一段时间在工作中,使用了流程审批,对api的调用非常不熟悉,都是调用别人写好的接口在界面上进行显示,基本了解了流程审批的主要步骤,现对流程审批进行学习,主要是调用api进行CRUD操作,感 ...

  4. Nodejs-搭建Nodejs开发环境

    学习nodejs,需要一个好的开发工具,并不想用无智能提示和不友好格式的记事本编写 1. 从www.nodejs.org下载nodejs并安装到指定的目录. 2. 下载一个开发工具, 可以选择webs ...

  5. 提高安全性而在HTTP响应头中可以使用的各种响应头字段

    本文介绍在Web服务器做出响应时,为了提高安全性而在HTTP响应头中可以使用的各种响应头字段.由于部分浏览器中有可能对某些字段或选项不提供支持,所以在使用这些字段时请先确认客户端环境. X-Frame ...

  6. [杂谈] My Wikipedia

    // 此博文为迁移而来,写于2015年6月8日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w3de.html

  7. 【BZOJ2038】【2009国家集训队】小Z的袜子(hose) 分块+莫队

    Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命……具体来说,小Z把这N只袜 ...

  8. 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener

    严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...

  9. 华清远见金牌讲师名家大讲堂Android开发篇成功举办

    2014年3月5日.12日华清远见金牌讲师名家大讲堂(以下简称名家大讲堂)在线讲座全新升级开讲,至此拉开了新一年名家大讲堂的序幕! 华清远见名家大讲堂作为业内颇具影响力的公益免 费线上课程,自2009 ...

  10. CentOS VirtualBox启动虚拟及报错:VirtualBox error: Kernel driver not installed (rc=1908)

    VirtualBox error: Kernel driver not installed (rc=1908) Hi all, Let me first say that this is my fin ...