CodeForces 761D Dasha and Very Difficult Problem
来源:互联网 发布:淘宝上的优惠券在哪领 编辑:程序博客网 时间:2024/06/05 15:38
题目链接:http://codeforces.com/contest/761/problem/D
题意:有一个序列c由序列a和b构造,c[i] = b[i]-a[i],现告诉你a和b中的元素范围都在l和r内,现告诉你a这个序列的元素,在告诉你c这个序列的排名即p[i]代表c[i]在c中为第几小,问你能否构造出一个b序列来
解析:首先由公式可以得到,b[i] = a[i]+c[i],但是现在c[i]不知道,不过可以通过对p[i]加上一个常数使得b[i] = a[i]+p[i]+k,相当于现在的问题就转化为,对于一个序列b,能否把b[i]加上一个常数,使得b[i]处于l和r的范围中,那么求一下b的最小值minn和最大值maxx,判断b的这个范围能否被lr这个范围覆盖,如果就把b这个序列移动最小值和l对齐,这样b就求出来了,否则就输出-1
#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>#include <queue>#include <map>using namespace std;const int maxn = 1e6+100;const int inf = 0x7fffffff;int a[maxn];int b[maxn];int p[maxn];int main(void){ int n,l,r; scanf("%d %d %d",&n,&l,&r); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) scanf("%d",&p[i]); int minn = inf,maxx = 0; for(int i=0;i<n;i++) { b[i] = a[i]+p[i]; minn = min(minn,b[i]); maxx = max(maxx,b[i]); } if(maxx-minn>r-l) puts("-1"); else { int tt = l-minn; for(int i=0;i<n;i++) { if(i)printf(" "); printf("%d",tt+b[i]); } puts(""); } return 0;}
0 0
- 【codeforces 761D】Dasha and Very Difficult Problem
- Codeforces 761D-Dasha and Very Difficult Problem
- 【Codeforces 761 D Dasha and Very Difficult Problem】
- CodeForces 761D Dasha and Very Difficult Problem
- Codeforces 761D-Dasha and Very Difficult Problem 贪心
- 761D Dasha and Very Difficult Problem
- Codeforces 394 D. Dasha and Very Difficult Problem 贪心
- D. Dasha and Very Difficult Problem
- 761D Dasha and Very Difficult Problem[数学][思维]
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心
- Codeforces Round #394 (Div. 2)D. Dasha and Very Difficult Problem【贪心】
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心,二分
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem —— 贪心
- D. Dasha and Very Difficult Problem----思维题
- Codeforces Round #394 (Div. 2)Dasha and Very Difficult Problem
- Codeforces Round #394 (Div. 2) Dasha and Very Difficult Problem
- 【codeforces 761A】Dasha and Stairs
- Mysql的分页优化
- 智能指针之shared_ptr
- wamp环境使用
- 如何生成静态页面的五种方案
- 一个封装了 7z 压缩解压功能的接口
- CodeForces 761D Dasha and Very Difficult Problem
- HDU1269迷宫城堡(Tarjan模板题)
- |Hdu 3622|2-SAT|二分|Bomb Game
- Unity3D游戏优化方案
- C程序下的深度冒泡排序
- 矩阵中的路径
- Codeforces Round #406 (Div. 1) C. Till I Collapse(可持久化线段树)
- 编写一个学生信息系统的菜单程序,在菜单其中的增加记录的菜单选项中实现对一条学生记录的录入,记录中需要有学号、姓名、性别,年龄籍贯等字段,要求用最合适的控件录入。
- 蓝桥杯 煤球数目