D. Dasha and Very Difficult Problem 二分
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 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 二分的更多相关文章
- 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 ...
- 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 ...
- Codeforces 761D Dasha and Very Difficult Problem(贪心)
题目链接 Dasha and Very Difficult Problem 求出ci的取值范围,按ci排名从小到大贪心即可. 需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解. #in ...
- 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 ...
- 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序列的 ...
- codeforces 761D - Dasha and Very Difficult Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【codeforces 761D】Dasha and Very Difficult Problem
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- BNU 4356 ——A Simple But Difficult Problem——————【快速幂、模运算】
A Simple But Difficult Problem Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %l ...
- 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 ...
随机推荐
- Jenkins系列之-—03 修改Jenkins用户的密码
一.Jenkins修改用户密码 Jenkins用户的数据存放在JENKINS_HOME/users目录. 1. 打开忘记密码的用户文件夹,里面就一个文件config.xml.打开并找到<pass ...
- IEnumerator<TItem>和IEnumerator Java 抽象类和普通类、接口的区别——看完你就顿悟了
IEnumerable 其原型至少可以说有15年历史,或者更长,它是通过 IEnumerator 来定义的,而后者中使用装箱的 object 方式来定义,也就是弱类型的.弱类型不但会有性能问题,最主要 ...
- github远程仓储和本地仓储进行关联
我们使用github作为远程仓储,需要提前注册号一个github账号 由于github仓储和本地仓储之间传输是使用ssh加密的,所以需要一点设置, 1.创建sshkey gitbash执行: ssh ...
- Java中有多少种设计模式?请简单画一下三种常见设计模式的类图?
转载:http://blog.csdn.net/longyulu/article/details/9159589 一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽 ...
- BootstrapValidator demo
source:http://bv.doc.javake.cn/api/ BootstrapValidator is the best jQuery plugin to validate form fi ...
- java 使用xom对象数据序列化为xml、反序列化、Preferences相关操作小案例
package org.rui.io.xml; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import ...
- 【转】 Android Studio --“Cannot resolve symbol” 解决办法
Android Studio 无法识别同一个 package 里的其他类,将其显示为红色,但是 compile 没有问题.鼠标放上去后显示 “Cannot resolve symbol XXX”,重启 ...
- html页面缓存问题
若IIS没有设置,html页面一旦缓存,则永远缓存. Chrome如下 火狐如下 一种方法:我们一般通过xxx.html?20151010这样URL欺骗浏览器. 另一种方法:设置IIS,让永远客户端不 ...
- apple IOS的base64编解码
<pre style="word-wrap: break-word; white-space: pre-wrap;">/* * Copyright (c) 2003 A ...
- OC:数组排序、时间格式化字符串
数组排序 //不可变数组的排序 NSArray * arr = [NSArray arrayWithObjects:@"hellow", @"lanou", @ ...