二分。

二分一下答案,然后验证一下。

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<stack>
  11. #include<iostream>
  12. using namespace std;
  13. typedef long long LL;
  14. const double pi=acos(-1.0),eps=1e-;
  15. void File()
  16. {
  17. freopen("D:\\in.txt","r",stdin);
  18. freopen("D:\\out.txt","w",stdout);
  19. }
  20. template <class T>
  21. inline void read(T &x)
  22. {
  23. char c=getchar(); x=;
  24. while(!isdigit(c)) c=getchar();
  25. while(isdigit(c)) {x=x*+c-''; c=getchar();}
  26. }
  27.  
  28. const int maxn=;
  29. LL k,a[maxn],b[maxn];
  30. int n;
  31.  
  32. bool check(LL x)
  33. {
  34. LL sum=;
  35. for(int i=;i<=n;i++)
  36. {
  37. if(a[i]*x<=b[i]) continue;
  38. sum=sum+a[i]*x-b[i];
  39. if(sum>k) return ;
  40. }
  41. if(sum<=k) return ;
  42. return ;
  43. }
  44.  
  45. int main()
  46. {
  47. scanf("%d%lld",&n,&k);
  48. for(int i=;i<=n;i++) scanf("%lld",&a[i]);
  49. for(int i=;i<=n;i++) scanf("%lld",&b[i]);
  50.  
  51. LL L=,R=3e9,ans;
  52. while(L<=R)
  53. {
  54. LL mid=(L+R)/;
  55. if(check(mid)) L=mid+,ans=mid;
  56. else R=mid-;
  57. }
  58. printf("%lld\n",ans);
  59.  
  60. return ;
  61. }

CodeForces 670D Magic Powder的更多相关文章

  1. Codeforces 670D1. Magic Powder - 1 暴力

    D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...

  2. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  3. CodeForces 670D2 Magic Powder - 2 (二分)

    题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...

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

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

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

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

  7. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  8. D2 Magic Powder -1/- 2---cf#350D2(二分)

    题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...

  9. Codefroces D2. Magic Powder - 2(二分)

    http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...

随机推荐

  1. discuz的门户文章页中增加百度分享代码

    discuz虽然有百度分享插件,但是不太想用,于是自己手动添加了百度分享代码: 一.在http://share.baidu.com/地址中申请设置自己的百度分享代码,选择的风格完全按照个人喜好进行选择 ...

  2. Go语言及Web框架Beego环境无脑搭建

    [原]Go语言及Web框架Beego环境无脑搭建 本文涉及软件均以截至到2013年10月12日的最新版本为准 1. 相关软件准备: 1) go1.2rc1.windows-386.msi,对应32位w ...

  3. (转)cin、cin.get()、cin.getline()、getline()、gets()等函数的用法

    学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有所帮助,如果有差错的地方还请各位多多指教(本文所有程序均通过VC 6.0运行)转载请保留作者信息:1.cin1 ...

  4. UAC权限

    .NET中提升UAC权限的方法总结   [题外话] 从Vista开始,由于增加了UAC(用户账户控制,User Account Control)功能,使得管理员用户平时不再拥有能控制所有功能的管理员权 ...

  5. ASP.NET Web API 基础篇1

    ASP.NET Web API 直到我膝盖中了一箭[1]基础篇 无题 蓦然回首,那些年,我竟然一直很二. 小时候,读武侠小说的时候,看到那些猪脚,常常会产生一种代入感,幻想自己也会遭遇某种奇遇,遇到悬 ...

  6. Redis几个认识误区

    前几天微博发生了一起大的系统故障,很多技术的朋友都比较关心,其中的原因不会超出James Hamilton在On Designing and Deploying Internet-Scale Serv ...

  7. Windows Socket 组件 HP-Socket v2.2.3

    高性能 Windows Socket 组件 HP-Socket v2.2.3 正式发布 HP-Socket 是一套通用的高性能 Windows Socket 组件包,包含服务端组件(IOCP 模型)和 ...

  8. 强烈推荐:240多个jQuery插件【转】

    强烈推荐:240多个jQuery插件 概述 jQuery 是继 prototype 之后又一个优秀的 Javascript 框架.其宗旨是—写更少的代码,做更多的事情.它是轻量级的 js 库(压缩后只 ...

  9. jquery mobile扁平化设计样式--Jquery mobile Flat UI介绍

    jquery mobile扁平化设计样式--Jquery mobile Flat UI介绍 这几天开发的web app使用了jquery mobile,jquery mobile自带的样式比较适合做企 ...

  10. 【Machine Learning】单参数线性回归 Linear Regression with one variable

        最近开始看斯坦福的公开课<Machine Learning>,对其中单参数的Linear Regression(未涉及Gradient Descent)做个总结吧. [设想]    ...