【Codeforces Round #299 (Div. 2) E】Tavas and Pashmaks
【链接】 我是链接,点我呀:)
【题意】
游泳+跑步比赛。
先游泳,然后跑步.
最先到终点的人是winner.
但是现在游泳的距离和跑步的距离长度都不确定。
S和R.
给你n个人,告诉你每个人游泳的速度以及它们跑步的速度。
现在问你在改变S,R的情况下,第i个人有没有可能为winner.
输出所有可能为winner的人的编号。
【题解】
每个人所花费的时间为$\frac{S}{si} + \frac{R}{ri}$
可以看成是向量{S,R}和($\frac{1}{si}$,$\frac{1}{ri}$)的点积。
考虑点积的几何意义为向量上的投影长度。
而一堆点里面,和某个固定的向量的投影长度.↓↓
会发现,总是凸包的边界上的某个点。
接下来的思路来自这里[我是一个链接](http://blog.csdn.net/fearlessxjdx/article/details/73327063?readlog)
看完思路之后接着
则,只要求出凸包。
然后找最坐标的x值最小的点就好(有多个x相同就找y尽量小的);
->求完凸包之后,因为排了个序,ch[0]就是这个最左的点。
然后找一个y值为最小的点就好了。
(多个最小,直接取x最小的就好);
所以求完凸包之后,顺序枚举,找到一个y=y的最小值,那么这一段就是所需的了。
重复点不要忘记加上去~就是那个to.
【代码】
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
int id;
Point() {}
Point(double x, double y) {
this->x = x;
this->y = y;
}
void read(int id) {
int s, b;
scanf("%d%d", &s, &b);
x = 1000000.0 / s; y = 1000000.0 / b;
this->id = id;
}
};
const double eps = 1e-16;
int dcmp(double x) {
if (fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
typedef Point Vector;
Vector operator + (Vector A, Vector B) {
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (Vector A, Vector B) {
return Vector(A.x - B.x, A.y - B.y);
}
Vector operator * (Vector A, double p) {
return Vector(A.x * p, A.y * p);
}
Vector operator / (Vector A, double p) {
return Vector(A.x / p, A.y / p);
}
bool operator < (const Point& a, const Point& b) {
return a.x < b.x || (dcmp(a.x - b.x) == 0 && a.y < b.y);
}
bool operator == (const Point& a, const Point& b) {
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //点积
double Length(Vector A) {return sqrt(Dot(A, A));} //向量的模
double Angle(Vector A, Vector B) {return acos(Dot(A, B) / Length(A) / Length(B));} //向量夹角
double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //叉积
double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} //有向面积
struct Line {
Point v, p;
Line() {}
Line(Point v, Point p) {
this->v = v;
this->p = p;
}
Point point(double t) {
return v + p * t;
}
};
//向量旋转
Vector Rotate(Vector A, double rad) {
return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
}
Vector AngleBisector(Point p, Vector v1, Vector v2){//给定两个向量,求角平分线
double rad = Angle(v1, v2);
return Rotate(v1, dcmp(Cross(v1, v2)) * 0.5 * rad);
}
//判断3点共线
bool LineCoincide(Point p1, Point p2, Point p3) {
return dcmp(Cross(p2 - p1, p3 - p1)) == 0;
}
//判断向量平行
bool LineParallel(Vector v, Vector w) {
return Cross(v, w) == 0;
}
//判断向量垂直
bool LineVertical(Vector v, Vector w) {
return Dot(v, w) == 0;
}
//计算两直线交点,平行,重合要先判断
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
Vector u = P - Q;
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
}
//点到直线距离
double DistanceToLine(Point P, Point A, Point B) {
Vector v1 = B - A, v2 = P - A;
return fabs(Cross(v1, v2)) / Length(v1);
}
//点到线段距离
double DistanceToSegment(Point P, Point A, Point B) {
if (A == B) return Length(P - A);
Vector v1 = B - A, v2 = P - A, v3 = P - B;
if (dcmp(Dot(v1, v2)) < 0) return Length(v2);
else if (dcmp(Dot(v1, v3)) > 0) return Length(v3);
else return fabs(Cross(v1, v2)) / Length(v1);
}
//点在直线上的投影点
Point GetLineProjection(Point P, Point A, Point B) {
Vector v = B - A;
return A + v * (Dot(v, P - A) / Dot(v, v));
}
//线段相交判定(规范相交)
bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
//可以不规范相交
bool SegmentProperIntersection2(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return max(a1.x, a2.x) >= min(b1.x, b2.x) &&
max(b1.x, b2.x) >= min(a1.x, a2.x) &&
max(a1.y, a2.y) >= min(b1.y, b2.y) &&
max(b1.y, b2.y) >= min(a1.y, a2.y) &&
dcmp(c1) * dcmp(c2) <= 0 && dcmp(c3) * dcmp(c4) <= 0;
}
//判断点在线段上, 不包含端点
bool OnSegment(Point p, Point a1, Point a2) {
return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
}
//n边形的面积
double PolygonArea(Point *p, int n) {
double area = 0;
for (int i = 1; i < n - 1; i++)
area += Cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
}
//点是否在多边形内部
int isPointInPolygon(Point o, Point *p, int n) {
int wn = 0;
for (int i = 0; i < n; i++) {
if (OnSegment(o, p[i], p[(i + 1) % n])) return -1;
int k = dcmp(Cross(p[(i + 1) % n] - p[i], o - p[i]));
int d1 = dcmp(p[i].y - o.y);
int d2 = dcmp(p[(i + 1) % n].y - o.y);
if (k > 0 && d1 <= 0 && d2 > 0) wn++;
if (k < 0 && d2 <= 0 && d1 > 0) wn--;
}
if (wn != 0) return 1;
return 0;
}
const int N = 200005;
int to[N];
//凸包
int ConvexHull(Point *p, int n, Point *ch) {
sort(p, p + n);
int m = 0;
memset(to, -1, sizeof(to));
//两个叉积改成<,可以求共线凸包
for (int i = 0; i < n; i++) {
to[i] = i;
if (i && p[i] == p[i - 1]) {
to[i] = to[i - 1];
continue;
}
while (m > 1 && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0) m--;
ch[m++] = p[i];
}
int k = m;
for (int i = n - 2; i >= 0; i--) {
while (m > k && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0) m--;
ch[m++] = p[i];
}
if (n > 1) m--;
return m;
}
Point a[N+10],ch[N+10];
bool vis[N+10];
int n,m;
double mi = 1e18;
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt","r",stdin);
#endif
scanf("%d",&n);
for (int i = 0;i < n;i++){
a[i].read(i);
}
m = ConvexHull(a,n,ch);
for (int i = 0;i < m;i++) mi = min(mi,ch[i].y);
for (int i = 0;i < m;i++){
vis[ch[i].id] = 1;
if (ch[i].y==mi) break;
}
for (int i = 0;i < n;i++)
if (vis[a[to[i]].id]) vis[a[i].id] = 1;
for (int i = 0;i < n;i++)
if (vis[i]){
printf("%d",i+1);
if (i==n-1) puts("");else putchar(' ');
}
return 0;
}
【Codeforces Round #299 (Div. 2) E】Tavas and Pashmaks的更多相关文章
- 【Codeforces Round #299 (Div. 2) D】Tavas and Malekas
[链接] 我是链接,点我呀:) [题意] 给你n个位置,然后让你从某些位置开始的|p|个位置,填上p这个字符串. 问你填的时候是否会发生冲突->输出0 否则输出最终n个位置组成的可能的字符串的总 ...
- 【Codeforces Round #299 (Div. 2) C】 Tavas and Karafs
[链接] 我是链接,点我呀:) [题意] 给你一个规则,让你知道第i根萝卜的高度为si = A+(i-1)*B 现在给你n个询问; 每次询问给你一个固定的起点l; 让你找一个最大的右端点r; 使得l. ...
- 【Codeforces Round #299 (Div. 2) B】Tavas and SaDDas
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每次取出最小的数字,在后面加上一个4或一个7就好; 会发现最后的数字很少的. [代码] #include <bits/stdc ...
- 【Codeforces Round #299 (Div. 2) A】 Tavas and Nafas
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题 [代码] #include <bits/stdc++.h> using namespace std; map & ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
随机推荐
- GridControl添加右键菜单
private void gridView1_MouseDown(object sender, MouseEventArgs e) { GridHitInfo vi = gridView1.CalcH ...
- python Tricks —— list 镜像复制与 list comprehension 列表解析的顺序
0. 对 list 镜像复制,a = [1, 2, 3] ⇒ [1, 2, 3, 3, 2, 1] a*2 ⇒ a = [1, 2, 3, 1, 2, 3] a.extend(reversed(a)) ...
- jQuery简单tab按钮切换
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- OpenCV —— 矩阵操作
多通道的矩阵 —— 通道是连续的!! 要将指向该数据类型的指针移动到下一通道,我们只需要将其增加1.如果想访问下一个“像素”或者元素集,则需要一定的偏移量 矩阵的step元素是矩阵中行的长度,单位为字 ...
- CSU 1046 追杀
Description 在一个8行9列的国际象棋棋盘上,有一名骑士在追杀对方的国王.该骑士每秒跨越一个2*3的区域,如下图所示. 而对方的国王慌忙落逃,他先沿着右下斜线方向一直跑,遇到边界以后会沿着光 ...
- 【Henu ACM Round #12 B】 Alice, Bob, Two Teams
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个前缀和 和 一个后缀和. (即前i个字符A所代表的数字的和以及前i个字符B所代表的数字的和.. 然后枚举前i个字符翻转. 求B对 ...
- GCC中-fpic解惑(转载)
参考: 1.<3.18 Options for Code Generation Conventions>2.<Options for Linking>3.<GCC -fP ...
- IIS特殊字符设置
简介:[iis7]请求筛选模块被配置为拒绝包含双重转义序列的请求.HTTP 错误 404.11 - Not Found 特殊字符最好替换成其他的字符,主要的特殊字符有”*”.”&”.”%”.” ...
- Mahout是什么?(一)
不多说,直接上干货! http://mahout.apache.org/ Mahout是Apache Software Foundation(ASF)旗下的一个开源项目. 提供一些可扩展的机器学习领域 ...
- Code froces 831 A. Unimodal Array
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...