Codeforces gym102058 J. Rising Sun-简单的计算几何+二分 (2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2))
1.0 s
1024 MB
standard input
standard output
Joon has a midterm exam tomorrow, but he hasn't studied anything. So he decided to stay up all night to study. He promised himself that he will not stop studying before the sun rises.
Joon's house is in some mountains. For convenience, let's say that Joon is living in a 2-dimensional coordinate system. The mountains are in the region y≥0y≥0, starting at x=a0x=a0, and the boundary of them consists of 2n2n line segments parallel to either y=xy=x or y=−xy=−x.
More precisely, the boundary of the mountains can be described by (2n−1)(2n−1) additional integers, where the iith number aiai of them is the xx-coordinate of the iith cusp of the mountains. The boundary line starts at (a0,0)(a0,0), proceeds parallel to y=xy=x until its xx-coordinate reaches a1a1, then proceeds parallel to y=−xy=−x until its xx-coordinate reaches a2a2, and so on. After the last step, the line proceeds parallel to y=−xy=−x until it meets the xx-axis.
The interior of the mountains is the region below the boundary and above the xx-axis. Thus, the interior and the boundary are disjoint.
At some point between x=a0x=a0 and x=a2n−1x=a2n−1, there is Joon's house on the boundary of the mountains. The size of his house is neglectable compared to the mountains.
Currently, the sun is at the origin and it rises vertically (+y+y direction), 1 per minute. Joon can see the sun if the interior of the mountains does not intersect the straight line segment connecting Joon's house and the sun. Joon is completely exhausted and wants to know when can he stop studying. But as you may expect, he is out of his mind, so he cannot do such difficult math. Help him!
The first line of the input contains an integer nn (1≤n≤1031≤n≤103).
The next line contains 2n2n integers, the iith of which is the integer ai−1ai−1 (1≤a0<⋯<a2n−1≤1061≤a0<⋯<a2n−1≤106).
The last line contains an integer xx, the xx-coordinate of Joon's house (a0≤x≤a2n−1a0≤x≤a2n−1).
It is guaranteed that the boundary of the mountains is in the region y≥0y≥0.
Print exactly one integer mm, the smallest integer such that Joon can see the sun after mm minutes.
2
1 4 6 7
7
5
2
3 4 5 7
7
0
3
4 9 12 13 14 16
15
8

Figure: Illustration of the first example.
题意就是给你山头的横坐标x,然后山的轮廓是一个山头到另一个山头的形状是与y=x或者y=-x平行的,坐标奇数是y=x平行的,偶数是与y=-x平行的,然后给你小孩家坐标的横坐标,他家在山的轮廓线上。
太阳沿着y轴垂直上升,一分钟还是一小时(忘了)上升1米,问你他什么时候能看到太阳。
直接先算出每个山头的横坐标,然后算出来小孩家的纵坐标,然后二分太阳的高度,通过太阳的坐标和小孩家的坐标,推出来直线的方程式,然后枚举每个山头,算出高度与实际的高度比较一下就可以了。
一开始直接枚举山头算直线,最后小数上取整,没过,改了二分过的,而且二分右界一开始设的1e6,wa44,改成1e8过的。。。
题目也小小暗示了二分,因为输出的是一个整数,OK
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+;
const int inf=0x3f3f3f3f; double a[maxn],b[maxn]; int main()
{
int n,pos;
cin>>n;
for(int i=;i<=*n;i++)
cin>>a[i];
cin>>pos;
double x,y;
double bb;
for(int i=;i<*n;i++){
x=a[i];y=b[i];
if(i%!=){
bb=y-x;
x=a[i+];y=x+bb;b[i+]=y;
}
else{
bb=y+x;
x=a[i+];y=(-)*x+bb;b[i+]=y;
}
}
x=a[*n];y=b[*n];
bb=y+x;
x=bb;y=;a[*n+]=x;b[*n+]=;
// for(int i=1;i<=2*n+1;i++){
// cout<<"("<<a[i]<<","<<b[i]<<")"<<endl;
// }
int cnt=;
double X=pos,Y;
for(int i=;i<=*n+;i++){
if(a[i]<X&&a[i+]>=X){
cnt=i+;
double k=(b[i]-b[i+])/(a[i]-a[i+]);
double bb=b[i]-k*a[i];
Y=k*X+bb;
break;
}
}
int ans=inf;
// for(int i=1;i<cnt;i++){
// double k=(Y-b[i])*1.0/(X-a[i]);
// double bb=Y-k*X;
// int flag=0;
// for(int i=1;i<cnt;i++){
// double h=k*a[i]+bb;
// if(h>=b[i]) continue;
// else{flag=1;break;}
// }
// if(flag==0) ans=min(ans,bb);
// }
// ans=ceil(ans);
// if(ans==-0) ans=0;
int l=,r=1e8+;
while(l<=r){
int mid=(l+r)>>;
double k=(Y-mid)/X;
double bb=Y-k*X;
int flag=;
for(int i=;i<cnt;i++){
double h=k*a[i]+bb;
if(h>=b[i]) continue;
else{flag=;break;}
}
if(flag==) r=mid-,ans=min(ans,mid);
else l=mid+;
}
cout<<ans<<endl;
}
Codeforces gym102058 J. Rising Sun-简单的计算几何+二分 (2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2))的更多相关文章
- Codeforces 828B Black Square(简单题)
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...
- 【bzoj1822】[JSOI2010]Frozen Nova 冷冻波 计算几何+二分+网络流最大流
题目描述 WJJ喜欢“魔兽争霸”这个游戏.在游戏中,巫妖是一种强大的英雄,它的技能Frozen Nova每次可以杀死一个小精灵.我们认为,巫妖和小精灵都可以看成是平面上的点. 当巫妖和小精灵之间的直线 ...
- codeforces 361 D. Levko and Array(dp+二分)
题目链接:http://codeforces.com/contest/361/problem/D 题意:最多可以修改K次数字,每次修改一个数字变成任意值,C=max(a[i+1]-a[i]):求操作之 ...
- codeforces 340C Tourist Problem(简单数学题)
题意:固定起点是0,给出一个序列表示n个点,所有点都在一条直线上,其中每个元素代表了从起点到这个点所走的距离.已知路过某个点不算到达这个点,则从起点出发,到达所有点的方案有许多种.求所有方案走的总路程 ...
- Codeforces 730 J.Bottles (01背包)
<题目链接> 题目大意: 有n个瓶子,各有水量和容量.现在要将这写瓶子里的水存入最少的瓶子里.问你最少需要的瓶子数?在保证瓶子数最少的情况下,要求转移的水量最少. 解题分析:首先,最少的瓶 ...
- Codeforces Gym101572 J.Judging Moose (2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017))
Problem J Judging Moose 这个题是这里面最简单的一个题... 代码: 1 //J 2 #include <stdio.h> 3 #include <math. ...
- codeforces#1163C2. Power Transmission (Hard Edition)(计算几何)
题目链接: https://codeforces.com/contest/1163/problem/C2 题意: 给出$n$个点,任意两点连接一条直线,求相交直线的对数 数据范围: $1 \le n ...
- Codeforces 749B:Parallelogram is Back(计算几何)
http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...
- HDU 4617 Weapon (简单三维计算几何,异面直线距离)
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
随机推荐
- Update SSM agent to each EC2 via Bat and bash script
1. copy the instance id from aws console to file 2. remove the , from file sed -i 's/,//g' file 3. g ...
- 图论:最短路-Bellman-Ford
我们之前介绍了一种,(最常用的)SPFA算法,SPFA算法是对Bellman-Ford算法的队列优化,用队列替代了Bellman-Ford中的循环检查部分 然后这里我们介绍Bellman-Ford算法 ...
- [洛谷P2577] [ZJOI2005]午餐
洛谷题目链接:[ZJOI2005]午餐 题目描述 上午的训练结束了,THU ACM小组集体去吃午餐,他们一行N人来到了著名的十食堂.这里有两个打饭的窗口,每个窗口同一时刻只能给一个人打饭.由于每个人的 ...
- [洛谷P4768] [NOI2018]归程 (kruskal重构树模板讲解)
洛谷题目链接:[NOI2018]归程 因为题面复制过来有点炸格式,所以要看题目就点一下链接吧\(qwq\) 题意: 在一张无向图上,每一条边都有一个长度和海拔高度,小\(Y\)的家在\(1\)节点,并 ...
- [洛谷P1404] 平均数
洛谷题目链接:平均数 题目描述 给一个长度为n的数列,我们需要找出该数列的一个子串,使得子串平均数最大化,并且子串长度>=m. 输入输出格式 输入格式: N+1行, 第一行两个整数n和m 接下来 ...
- EntitySpace 常用语句
EntitySpace 这个是很早期的ORM框架,最近发现这个破解的也都不能用了.有谁知道能用的,联系我. 1. where带几个条件的 query.Where(query.ProductTempSt ...
- Hadoop大数据生态系统及常用组件(山东数漫江湖)
经过多年信息化建设,我们已经进入一个神奇的“大数据”时代,无论是在通讯社交过程中使用的微信.QQ.电话.短信,还是吃喝玩乐时的用到的团购.电商.移动支付,都不断产生海量信息数据,数据和我们的工作生活密 ...
- js基础知识点收集
js基础知识点收集 js常用基本类型 function show(x) { console.log(typeof(x)); // undefined console.log(typeof(10)); ...
- 在电脑中配置adb
在环境变量的系统变量path中添加SDK中platform_tools和tools的路径 如果出现version说明配置成功
- 直观理解js自执行函数
要在函数体后面加括号就能立即调用,则这个函数必须是函数表达式,不能是函数声明: Jslint推荐的写法: (function(){alert(1);}()); 针对函数声明,使用().!.+.-.=. ...