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 ...
随机推荐
- Dropbox电面面经
他家电面有2轮,等待onsite.. . 电面1: 国人MM面的.这点感觉非常难得. 统计近期5分钟的点击量,实现hit和getHit两个函数.这题是他家高频题,我用deque实现的,hit的均摊时间 ...
- Selenium系列之--04 常见元素操作总结
一.Selenium总共有八种定位方法 By.id() 通过id定位 By.name() 通过name 定位 By.xpath() 通过xpath定位 By.className() 通过clas ...
- Oracle 模糊查询方法
在这个信息量剧增的时代,怎样帮助用户从海量数据中检索到想要的数据.模糊查询是不可缺少的. 那么在Oracle中模糊查询是怎样实现的呢? 一.我们能够在where子句中使用likeke ...
- Linux_C——动态库,静态库
/usr/lib /lib:标准系统库文件 库是一组预先编译好的函数的集合,这些函数都是按照可重用的原则编写的.它们通常有一组相互关联的函数组成以 执行某项常见的任 ...
- 6 使用Ionic开发天气应用
简介:本节课我们会制作一款天气应用,这款应用允许用户查看当前的天气情况.天气预报以及地点收藏,在模态框内显示日出和日落的数据,使用分页滚动面板显示天气信息,使用侧滑菜单实现导航. 6.1 项目配置 环 ...
- S2SH的集成(Struts2,Spring,Hibernate)----青软S2SH(笔记)
- [Unity3D]Unity3D游戏开发之连续滚动背景
在诸如天天跑酷等2D游戏中.因为游戏须要表现出运动的感觉.通常都会使游戏背景连续循环滚动以增强视觉效果,那么今天.博主就来带领大家一起来实现连续滚动背景吧. 首先来讲述一下原理.准备两张连续的图片(博 ...
- shell脚本常用(记)
1.变量检查,判空 a.直接变量判断 if [ ! $1 ];then ..empty..fi b.变量通过" "引号引起来 if [ ! -n "$1" ...
- mongo14-----group,aggregate,mapReduce
group,aggregate,mapReduce 分组统计: group() 简单聚合: aggregate() 强大统计: mapReduce() db.collection.group(docu ...
- C++在循环内和循环外定义变量的差异
原文:http://blog.csdn.net/cashey1991/article/details/45127561 最后总结: 对于使用int等基本数据类型作为循环变量,只要你用的优化方面足够给力 ...