当前位置: 首页 > news >正文

北京智能网站建设哪里好十大品牌营销策划公司

北京智能网站建设哪里好,十大品牌营销策划公司,网站建设工作的函,网站建设与制作的流程2021 ICPC 昆明 I Mr. Main and Windmills(直线与线段的交点) I Mr. Main and Windmills 大意:给出一条线段 , 一个人从线段的起点走到线段的终点 , 线段的一侧有若干风车 , 当前的人在线段上的每一个位置观察风车都会得到一个顺…

2021 ICPC 昆明 I Mr. Main and Windmills(直线与线段的交点)

I Mr. Main and Windmills

大意:给出一条线段 , 一个人从线段的起点走到线段的终点 , 线段的一侧有若干风车 , 当前的人在线段上的每一个位置观察风车都会得到一个顺序 。多次询问第 i 号风车被观察的位置第k次改变时人在线段上的位置。

思路:不难发现 , 两个风车交换位置当且仅当人走过 两风车所在直线与线段交点的时候 , 两两枚举风车求直线与线段交点 , 然后根据和起始点的距离排序后根据要求输出即可。

易错点:这里线段与直线求交会有一个易错点。

如果先求 线段所在直线与风车直线的交点(line_make_point) , 然后再判断交点是否在线段上(point_on_segment) , 这样误差会巨大。因为直线求交会有除法 , 求出的交点存在误差 ,然后判断点在线段上时会用到叉积 , 叉积的几何意义就是形成三角形的面积 , 如果线段特别特别长 , 叉积就会很大 , 从而在这里产生错误。

if(!line_make_point(l , r , now)) continue;
if(!point_on_segment(now , st , ed)) continue;

解决方法:

1. 对于求交问题 , 先判断在求交

对应在这里 , 就可以先判断线段和直线是否相交(toleft) , 相交求交点即可 , 这样是不会有判断误差的产生的。

if(toleft(st , p[i] , p[j]) * toleft(ed , p[i] , p[j]) > 0) continue;
line_make_point(l , r , now);

2. double 换成 long double , 容限(eps) 调大即可

这里推荐第一种 , 第一种更规范

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;//--------------------------------------------------------------
const double eps = 1e-9;
const double pi = acos(-1);
inline double sqr(double x) {return x * x;} //平方
int sign(double x){if(fabs(x) < eps) return 0;if(x > 0) return 1;return -1;
}//符号
struct point{double x , y;point(){}point(double a , double b) : x(a) , y(b){}friend point operator + (const point &a , const point &b){return point(a.x + b.x , a.y + b.y);}friend point operator - (const point &a , const point &b){return point(a.x - b.x , a.y - b.y);}friend bool operator == (const point &a , const point &b){return !sign(a.x - b.x) && !sign(a.y - b.y);}friend point operator * (const point &a , const double &b){return point(a.x * b , a.y * b);}friend point operator * (const double &a , const point &b){return point(a * b.x , a * b.y);}friend point operator / (const point &a , const double &b){return point(a.x / b , a.y / b);}//向量模长 double norm(){ return sqrt(sqr(x) + sqr(y));}
}; struct line{point a , b;line(){}line(point x , point y) : a(x) , b(y) {}
};double det(const point &a , const point &b){return a.x * b.y - a.y * b.x;
}//叉积 判断两点共线 double dot(const point &a , const point &b){return a.x * b.x + a.y * b.y;
}//点积double dist(const point &a , const point &b){return (a - b).norm();
}//两点距离point rotate_point(const point &a , const point &p , double A){double tx = p.x - a.x , ty = p.y - a.y;return point(a.x + tx * cos(A) - ty * sin(A) , a.y + tx * sin(A) + ty * cos(A));
}// p 点 绕 a 点逆时针旋转 A 弧度int toleft(const point &p , const point &a , const point &b) {return sign(det(b - a , p - a));// 1 左 0 上 -1 右
}//只适用凸多边形//判断点 p 是否在线段 st 上(包括端点)
bool point_on_segment(point p , point s , point t){return sign(det(p - s , t - s)) == 0 && sign(dot(p - s , p - t)) <= 0;
}bool parallel(line a , line b){return !sign(det(a.a - a.b , b.a - b.b));
}bool line_make_point(line a , line b , point &res){if(parallel(a , b)) return 0;double s1 = det(a.a - b.a , b.b - b.a);double s2 = det(a.b - b.a , b.b - b.a);res = (s1 * a.b - s2 * a.a) / (s1 - s2);return 1;
}
//--------------------------------------------------------------
//--------------------------------------------------------------int n , m;
point st , ed , p[N] , now;
double x , y;
int h , k;vector<tuple<double , double , double>>ans[N];signed main(){IOScout << fixed << setprecision(10);cin >> n >> m;cin >> x >> y;st = point{x , y};cin >> x >> y;ed = point{x , y};for(int i = 1 ; i <= n ; i ++){cin >> x >> y;p[i] = point{x , y};}line l = line{st , ed};for(int i = 1 ; i <= n ; i ++){for(int j = i + 1 ; j <= n ; j ++){line r = line{p[i] , p[j]};if(toleft(st , p[i] , p[j]) * toleft(ed , p[i] , p[j]) > 0) continue;line_make_point(l , r , now);ans[i].emplace_back(now.x , now.y , dist(now , st));ans[j].emplace_back(now.x , now.y , dist(now , st));} }for(int i = 1 ; i <= n ; i ++) sort(ans[i].begin() , ans[i].end() , [&](tuple<double , double , double> a , tuple<double , double , double> b){return get<2>(a) < get<2>(b);});for(int i = 1 ; i <= m ; i ++){cin >> h >> k;if(ans[h].size() < k){cout << "-1\n";}else{auto [x , y , z] = ans[h][k - 1];cout << x << " " << y << "\n";}}return 0;
}
//freopen("文件名.in","r",stdin);
//freopen("文件名.out","w",stdout);
http://www.15wanjia.com/news/34706.html

相关文章:

  • 新乡彩票网站建设新手电商运营从哪开始学
  • 阿拉尔建设局网站爱网站关键词挖掘
  • 淘宝客做网站链接竞价推广托管服务
  • 做游戏装备网站可以吗企业站seo价格
  • 第一次做怎么放进去视频网站全网推广方案
  • 什么浏览器好用可以看任何网站新型网络营销方式
  • 外贸购物网站制作站内seo内容优化包括
  • 深圳市建筑工务署关键词优化报价推荐
  • 企业网站的重要性百度软件市场
  • 网站开发培训合肥如何建立一个网站
  • 网站使用网络图片做素材 侵权东莞谷歌推广
  • 网站营销信息广州seo黑帽培训
  • n加1网站建设开发新客户的十大渠道
  • 解析网站接口怎么做百度在线搜索
  • 在线黑科技网站百度推广搜索排名
  • 苏州 网站制作公司网图识别在线百度
  • 石家庄网站建设企业磁力狗在线引擎
  • 官方网站找oem做洗发水厂家宁波seo外包推广平台
  • 网站建设实训的报告品牌策划与推广方案
  • jsp网站建设美食google adsense
  • 网站建设制作百度知道官网首页登录入口
  • wordpress 手机站目录微博推广价格表
  • 内蒙古网站建设百度怎么推广app
  • 如何在服务器上做网站上海网站建设关键词排名
  • 去哪个网站可以接单做ps等等推广app是什么工作
  • 织梦模板下载商城网站模板(高端大气上档次:带数据)seo是什么的缩写
  • 郑州免费网站制作百度竞价开户哪家好
  • 涪城移动网站建设沈阳seo按天计费
  • 广州网站制作企业热搜榜排名前十
  • 网站上的截图怎么做企业网站推广效果指标分析