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 ...
随机推荐
- ASP.NET MVC3 自定义编辑模版
在View中显示Model中的各字段,默认是使用htmlhelper的EditorFor方法,在界面上显示的文本框.而使用EditorTemplates可在View上为特定字段显示自定义的界面.比如购 ...
- [他山之石]Google's Project Oxygen Pumps Fresh Air Into Management
The Project Oxygen team spent one year data-mining performance appraisals, employee surveys, nominat ...
- JAVA泛型类
泛型是JDK 5.0后出现新概念,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. 泛型类引入的好处不 ...
- Restrictions.or多个条件用法
两个条件或查询: Restrictions.or(Restrictions.in("username",list1),Restrictions.idEq(1)); 三个或多个条件查 ...
- Linux设备驱动--块设备(三)之程序设计
块设备驱动注册与注销 块设备驱动中的第1个工作通常是注册它们自己到内核,完成这个任务的函数是 register_blkdev(),其原型为:int register_blkdev(unsigned i ...
- Linux 打包classes
进入项目后 tar -zcvf ~/${HOSTNAME}-${PWD##*/}-$(date +%Y-%m-%d)-classes.tar.gz webapps/ROOT/WEB-INF/class ...
- Memcache存储大数据的问题(大于1m)
Memcached存储单个item最大数据是在1MB内,如果数据超过1M,存取set和get是都是返回false,而且引起性能的问题. 我们之前对排行榜的数据进行缓存,由于排行榜在我们所有sql se ...
- Velocity魔法堂系列一:入门示例(转)
Velocity魔法堂系列一:入门示例 一.前言 Velocity作为历史悠久的模板引擎不单单可以替代JSP作为Java Web的服务端网页模板引擎,而且可以作为普通文本的模板引擎来增强服务端程序文本 ...
- DateTime?转化为DateTime,int? 转 int
深入理解C#---1.可空类型 https://blog.csdn.net/tianzeyu1992/article/details/52618131 原文:https://blog.csdn.net ...
- P1971 [NOI2011]兔兔与蛋蛋游戏
传送门 思路比较迷--题解在这里 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) for(R ...