http://codeforces.com/contest/761/problem/D

c[i] = b[i] - a[i],而且b[]和a[]都属于[L, R]

现在给出a[i]原数组和c[i]的相对大小,要确定b[i]

因为已经知道了c[i]的相对大小,那么从最小的那个开始,那个肯定是选了L的了,因为这样是最小的数,

然后因为c[i]要都不同,那么记录最小的那个c[]的大小是mx,那么下一个就要是mx + 1,就是倒数第二小的那个。

也就是b[i]在[L, R]中选一个数,使得b[i] - a[i] >= mx,当然这个数越小越好,为后面留空间。

这个时候可以二分出这个数就好了。

 4 2 109
4 109 4 7
1 2 3 4
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <assert.h>
  7. #define IOS ios::sync_with_stdio(false)
  8. using namespace std;
  9. #define inf (0x3f3f3f3f)
  10. typedef long long int LL;
  11.  
  12. #include <iostream>
  13. #include <sstream>
  14. #include <vector>
  15. #include <set>
  16. #include <map>
  17. #include <queue>
  18. #include <string>
  19. #include <bitset>
  20. const int maxn = 1e5 + ;
  21. int a[maxn];
  22. struct node {
  23. int id, val;
  24. bool operator < (const struct node & rhs) const {
  25. return val < rhs.val;
  26. }
  27. }c[maxn];
  28. map<int, bool>mp;
  29. int ans[maxn];
  30. bool check(int val, int mx, int a) {
  31. return val - a >= mx;
  32. }
  33. void work() {
  34. int n, L, R;
  35. scanf("%d%d%d", &n, &L, &R);
  36. for (int i = ; i <= n; ++i) {
  37. scanf("%d", &a[i]);
  38. }
  39. for (int i = ; i <= n; ++i) {
  40. scanf("%d", &c[i].val);
  41. c[i].id = i;
  42. }
  43. sort(c + , c + + n);
  44. ans[c[].id] = L;
  45. int mx = L - a[c[].id];
  46. int touse = L;
  47. for (int i = ; i <= n; ++i) {
  48. mx++;
  49. int be = L, en = R;
  50. while (be <= en) {
  51. int mid = (be + en) >> ;
  52. if (check(mid, mx, a[c[i].id])) {
  53. en = mid - ;
  54. } else be = mid + ;
  55. }
  56. if (be > R) {
  57. cout << "-1" << endl;
  58. return;
  59. }
  60. ans[c[i].id] = be;
  61. mx = be - a[c[i].id];
  62. }
  63. for (int i = ; i <= n; ++i) {
  64. cout << ans[i] << " ";
  65. }
  66. }
  67.  
  68. int main() {
  69. #ifdef local
  70. freopen("data.txt", "r", stdin);
  71. // freopen("data.txt", "w", stdout);
  72. #endif
  73. work();
  74. return ;
  75. }

D. Dasha and Very Difficult Problem 二分的更多相关文章

  1. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心

    D. Dasha and Very Difficult Problem 题目连接: http://codeforces.com/contest/761/problem/D Description Da ...

  2. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem

    D. Dasha and Very Difficult Problem time limit per test:2 seconds memory limit per test:256 megabyte ...

  3. Codeforces 761D Dasha and Very Difficult Problem(贪心)

    题目链接 Dasha and Very Difficult Problem 求出ci的取值范围,按ci排名从小到大贪心即可. 需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解. #in ...

  4. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem —— 贪心

    题目链接:http://codeforces.com/contest/761/problem/D D. Dasha and Very Difficult Problem time limit per ...

  5. codeforces 761 D. Dasha and Very Difficult Problem(二分+贪心)

    题目链接:http://codeforces.com/contest/761/problem/D 题意:给出一个长度为n的a序列和p序列,求任意一个b序列使得c[i]=b[i]-a[i],使得c序列的 ...

  6. codeforces 761D - Dasha and Very Difficult Problem

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. 【codeforces 761D】Dasha and Very Difficult Problem

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. BNU 4356 ——A Simple But Difficult Problem——————【快速幂、模运算】

    A Simple But Difficult Problem Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %l ...

  9. HDU 4282 A very hard mathematic problem 二分

    A very hard mathematic problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sh ...

随机推荐

  1. Dropbox电面面经

    他家电面有2轮,等待onsite.. . 电面1: 国人MM面的.这点感觉非常难得. 统计近期5分钟的点击量,实现hit和getHit两个函数.这题是他家高频题,我用deque实现的,hit的均摊时间 ...

  2. Selenium系列之--04 常见元素操作总结

    一.Selenium总共有八种定位方法  By.id()  通过id定位 By.name()  通过name 定位 By.xpath() 通过xpath定位 By.className() 通过clas ...

  3. Oracle 模糊查询方法

           在这个信息量剧增的时代,怎样帮助用户从海量数据中检索到想要的数据.模糊查询是不可缺少的. 那么在Oracle中模糊查询是怎样实现的呢?   一.我们能够在where子句中使用likeke ...

  4. Linux_C——动态库,静态库

    /usr/lib /lib:标准系统库文件          库是一组预先编译好的函数的集合,这些函数都是按照可重用的原则编写的.它们通常有一组相互关联的函数组成以          执行某项常见的任 ...

  5. 6 使用Ionic开发天气应用

    简介:本节课我们会制作一款天气应用,这款应用允许用户查看当前的天气情况.天气预报以及地点收藏,在模态框内显示日出和日落的数据,使用分页滚动面板显示天气信息,使用侧滑菜单实现导航. 6.1 项目配置 环 ...

  6. S2SH的集成(Struts2,Spring,Hibernate)----青软S2SH(笔记)

  7. [Unity3D]Unity3D游戏开发之连续滚动背景

    在诸如天天跑酷等2D游戏中.因为游戏须要表现出运动的感觉.通常都会使游戏背景连续循环滚动以增强视觉效果,那么今天.博主就来带领大家一起来实现连续滚动背景吧. 首先来讲述一下原理.准备两张连续的图片(博 ...

  8. shell脚本常用(记)

    1.变量检查,判空 a.直接变量判断  if [ ! $1 ];then ..empty..fi b.变量通过" "引号引起来  if [ ! -n "$1" ...

  9. mongo14-----group,aggregate,mapReduce

    group,aggregate,mapReduce 分组统计: group() 简单聚合: aggregate() 强大统计: mapReduce() db.collection.group(docu ...

  10. C++在循环内和循环外定义变量的差异

    原文:http://blog.csdn.net/cashey1991/article/details/45127561 最后总结: 对于使用int等基本数据类型作为循环变量,只要你用的优化方面足够给力 ...