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

嘉兴做网站建设的公司/网站自动秒收录工具

嘉兴做网站建设的公司,网站自动秒收录工具,互联网行业公司,wordpress广告公司模板题意:给你一个圆形和很多个矩形,然后要你求圆形的圆周有多少被矩形覆盖。 思路:比赛的时候是有思路的了,不过一直在调别的题,最后剩下30分钟肯定来不及敲。想法是这样的,要是我们可以求出每个矩形覆盖了圆周…

题意:给你一个圆形和很多个矩形,然后要你求圆形的圆周有多少被矩形覆盖。

思路:比赛的时候是有思路的了,不过一直在调别的题,最后剩下30分钟肯定来不及敲。想法是这样的,要是我们可以求出每个矩形覆盖了圆周的哪些区间,我们最后就对这些区间排序然后求区间和就好了,但是问题是怎么知道哪些区间是要的,哪些区间是不要的呢? 首先我们对矩形的四条线段和矩形求交,把所有的交点求出来,然后将交点用atan2转化成极角(我用的区间是[0,2pi]),实际上直接用极角肯定也没问题吧),然后排序,排序之后我们会发现我们要的区间一定是相邻的两个角度的点对应的区间,但是有可能这些区间是不是我们要的,判断的条件就是两个角度的对应的弧段的中点如果在矩形里面的话我们就将这个区间保留。

如此一来就将所有的区间弄了出来,接下来就是求线段的并的总长度了,for一下就好。

但是后来WA了一发,原因是如果圆完全被矩形包含的话,我们解不出交点,会被默认答案是0,所以上面的方法只有在有交点的时候成立,所以判的时候加多一个判是否被完全包含,被完全包含最后直接输出2*pi*r就好,代码写的略长= =

#pragma warning(disable:4996)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#define maxn 150
#define eps 1e-7
using namespace std;const double pi = acos(-1.0);struct Point
{double x, y;Point(double xi, double yi) :x(xi), y(yi){}Point(){}Point operator + (const Point &b){return Point(x + b.x, y + b.y);}Point operator - (const Point &b){return Point(x - b.x, y - b.y);}double ang(){double res=atan2(y,x);if (res < 0) return res + 2*pi;else return res;}Point rot(double ag){return Point(x*cos(ag) - y*sin(ag), x*sin(ag) + y*cos(ag));}
};struct Seg
{Point st, ed;Seg(Point sti, Point edi) :st(sti), ed(edi){}Seg(){}
};struct Inter
{double l, r;Inter(double li, double ri) :l(li), r(ri){}Inter(){}bool operator < (const Inter &b) const{if (l == b.l) return r < b.r;else return l < b.l;}
};int dcmp(double x){return (x>eps) - (x < -eps);
}double ctr;
int n;vector<double> getInterSection(Seg seg){vector<double> res;if (seg.st.x == seg.ed.x){double xx = seg.st.x;double y1 = seg.st.y, y2 = seg.ed.y;if (dcmp(abs(xx) - ctr) > 0) return res;else if (dcmp(abs(xx) - ctr) == 0){if (0 >= y1 && 0 <= y2){res.push_back(Point(xx, 0).ang());}}else{double dy = sqrt(ctr*ctr - xx*xx);if (dy >= y1&&dy <= y2){res.push_back(Point(xx, dy).ang());}dy = -dy;if (dy >= y1&&dy <= y2){res.push_back(Point(xx, dy).ang());}}}else{double yy = seg.st.y;double x1 = seg.st.x, x2 = seg.ed.x;if (dcmp(abs(yy) - ctr) > 0) return res;else if (dcmp(abs(yy) - ctr) == 0){if (0 >= x1 && 0 <= x2){res.push_back(Point(0, yy).ang());}}else{double dx = sqrt(ctr*ctr - yy*yy);if (dx >= x1&&dx <= x2){res.push_back(Point(dx, yy).ang());}dx = -dx;if (dx >= x1&&dx <= x2){res.push_back(Point(dx, yy).ang());}}}return res;
}bool withinRect(double xx,double yy, double li, double lj, double ri, double rj){return xx >= li&&xx <= ri&&yy >= lj&&yy <= rj;
}int main()
{while (cin >> ctr >> n){double li, lj, ri, rj;Seg seg;vector<double> tot;vector<double> tmp;vector<Inter> inter; bool flag = false;for (int i = 0; i < n; i++){scanf("%lf%lf%lf%lf", &li, &lj, &ri, &rj);if (flag) continue;if (li <= -ctr && ctr <= ri && lj <= -ctr&&ctr <= rj){flag = true; continue;}tot.clear();seg.st = Point(li, lj); seg.ed = Point(li, rj);tmp = getInterSection(seg);tot.insert(tot.end(), tmp.begin(), tmp.end());seg.st = Point(ri, lj); seg.ed = Point(ri, rj);tmp = getInterSection(seg);tot.insert(tot.end(), tmp.begin(), tmp.end());seg.st = Point(li, lj); seg.ed = Point(ri, lj);tmp = getInterSection(seg);tot.insert(tot.end(), tmp.begin(), tmp.end());seg.st = Point(li, rj); seg.ed = Point(ri, rj);tmp = getInterSection(seg);tot.insert(tot.end(), tmp.begin(), tmp.end());sort(tot.begin(), tot.end());int siz = tot.size();for (int k = 0; k < siz; k++){if (dcmp(tot[k] - tot[(k + 1) % siz]) == 0) continue;Point mid;if (dcmp(tot[(k + 1) % siz] - tot[k])>0) mid = Point(ctr, 0).rot((tot[k] + tot[(k + 1) % siz]) / 2);else mid = Point(ctr, 0).rot((tot[k] + tot[(k + 1) % siz]-2*pi) / 2);if (withinRect(mid.x, mid.y, li, lj, ri, rj)){if (dcmp(tot[(k + 1) % siz] - tot[k]) >= 0){inter.push_back(Inter(tot[k], tot[(k + 1) % siz]));}else{inter.push_back(Inter(0, tot[(k+1)%siz]));inter.push_back(Inter(tot[k % siz], 2 * pi));}}}}sort(inter.begin(), inter.end());double ans = 0;if (flag) {printf("%.3lf\n", 2 * pi*ctr); continue;}if (inter.size() == 0) {printf("%.3lf\n", ans); continue;}double lt = inter[0].l, rt = inter[0].r;for (int i = 1; i < inter.size(); i++){if (inter[i].l <= rt){rt = max(rt, inter[i].r);}else{ans += rt - lt;lt = inter[i].l, rt = inter[i].r;}}ans += rt - lt;printf("%.3lf\n", ans*ctr);}return 0;
}

 

转载于:https://www.cnblogs.com/chanme/p/3643782.html

http://www.lbrq.cn/news/2343493.html

相关文章:

  • 网站设计公司佛山/百度热搜词排行榜
  • wordpress翻译教程/当阳seo外包
  • 呼叫中心网站建设/如何注册网址
  • 政府网站谁来做/四川二级站seo整站优化排名
  • 创新网站设计/全国培训机构排名前十
  • 网站建设行业怎么样/seo优化中商品权重主要由什么决定
  • 南宁推广软件/武汉seo优化服务
  • 怎么做网购网站/合肥seo优化排名公司
  • 国内做视频的网站有哪些/外链发布软件
  • 帝国网站数据库配置文件/2345网址中国最好
  • 云南商城网站建设/关键词你们懂的
  • 沈阳电子商务网站建设/百度seo推广
  • 新疆建设监理协会网站/百度灰色关键词技术
  • 搭建php网站环境/地推的方法和技巧
  • 做跨境网站注意事项/搜索引擎优化的具体操作
  • 网站后台换图片/bing收录提交
  • 怎么做信息采集的网站/深圳纯手工seo
  • 网站建设要学会编程吗/星链友店
  • wordpress 制作首页模板/简单网站建设优化推广
  • 南京html5网站建设/百度数据库
  • 公司做网站流程/友情链接是什么
  • 网站建设开票内容是什么意思/seochinazcom
  • 广告网站怎么设计制作/职业教育培训机构排名前十
  • 广东企业网站制作/关键词收录
  • java web网站开发流程/网站提交收录软件
  • 网站推广信息怎么做/百度一下官网搜索引擎
  • 软件测试培训需要多久/百度快速seo软件
  • 做类图的网站/软文生成器
  • 做网站在线支付系统多少钱/杭州seo公司服务
  • 做健康类网站怎么备案/网络营销的发展现状及趋势
  • AI辅助Python编程30天速成
  • 如何在simulink中怎么获取足端轨迹代码解释?
  • 鸿蒙开发NDK之---- 如何将ArkTs的类型转化成C++对应的类型(基础类型,包含部分代码解释)
  • 使用 pytest 测试框架构建自动化测试套件之一
  • Java项目:基于SSM框架实现的高校毕业选题管理系统【ssm+B/S架构+源码+数据库+毕业论文】
  • 各种开发语言主要语法对比