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
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e5 + ;
int a[maxn];
struct node {
int id, val;
bool operator < (const struct node & rhs) const {
return val < rhs.val;
}
}c[maxn];
map<int, bool>mp;
int ans[maxn];
bool check(int val, int mx, int a) {
return val - a >= mx;
}
void work() {
int n, L, R;
scanf("%d%d%d", &n, &L, &R);
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = ; i <= n; ++i) {
scanf("%d", &c[i].val);
c[i].id = i;
}
sort(c + , c + + n);
ans[c[].id] = L;
int mx = L - a[c[].id];
int touse = L;
for (int i = ; i <= n; ++i) {
mx++;
int be = L, en = R;
while (be <= en) {
int mid = (be + en) >> ;
if (check(mid, mx, a[c[i].id])) {
en = mid - ;
} else be = mid + ;
}
if (be > R) {
cout << "-1" << endl;
return;
}
ans[c[i].id] = be;
mx = be - a[c[i].id];
}
for (int i = ; i <= n; ++i) {
cout << ans[i] << " ";
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

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. Sql Server 导入还有一个数据库中的表数据

    在涉及到SQL Server编程或是管理时一定会用到数据的导入与导出, 导入导出的方法有多种,此处以SQL Server导入表数据为例.阐述一下: 1.打开SQL Server Management ...

  2. 发挥bat的作用

    from 转自:http://blog.csdn.net/hitlion2008/article/details/7467252 1.什么是Windows BATCH BATCH也就是批处理文件,有时 ...

  3. Oracle11g表空间导入dmp数据

    如果你的表数据没有附带表空间和用户名,那么只要一句话 Imp {u_name}/{u_pwd}@{local_svrname} fromuser={from_user} touser={u_name} ...

  4. MySQL的引入,绿色包下载和应用

    一.下载MySQL绿色版 1.下载地址: 以下是MySQL最新绿色版链接(都是来源于oracle官网),点击以下链接直接下载. 1.1.官网链接:https://www.oracle.com/inde ...

  5. 编程题:1. var person = '{name:"Lily",sex:"famale",age:24,country:"US"}';将person转换成JSON对象并便利每个属性值。

    /// <summary> /// Json工具类 /// </summary> public class JsonUtility { private static JsonU ...

  6. python和python3

    1 安装python和python3的方法 如果是python,那么直接python setup.py install; 如果是python3,那么直接python3 setup.py install ...

  7. 基于TCP的字符串传输程序

    ---恢复内容开始--- LINUX中的网络编程是通过SOCKET接口来进行的. Socket(套接字) Socket相当于进行网络通信两端的插座,只要对方的Socket和自己的Socket有通信联接 ...

  8. Maven运行测试

    原文:http://tianya23.blog.51cto.com/1081650/292315/ Maven运行用于测试中的最佳实践(个人认为,呵呵)   1.创建maven工程 mvn arche ...

  9. mac多线程下载神器

    本文参考:https://blog.csdn.net/orangleliu/article/details/46834429 神器:axel 安装(已经安装homebrew前提下,没有请参考:http ...

  10. I.MX6 查找占用UART进程

    /**************************************************************************** * I.MX6 查找占用UART进程 * 说 ...