题目链接 https://codeforces.com/gym/101917

E

题意:给定一个多边形(n个点),然后逆时针旋转A度,然后对多边形进行规约,每个点的x规约到[0,w]范围内,y规约到[0,h]范围内,输出规约后的结果。

解析:求出来 多边形的长和宽,再和w,h比较,对点按比例进行缩放就好了。 (多边形旋转其实是绕给出的第一个点旋转,以为是绕原点wa了1发)。

AC代码

  1. #include <bits/stdc++.h>
  2. #define Vector Point
  3. using namespace std;
  4. typedef long long ll;
  5. const double eps = 1e-;
  6. const double PI=acos(-);
  7. const int maxn = 1e5+,inf=0x3f3f3f3f;
  8. //head-------------------------------------------------------------------
  9. int dcmp(double x) { return fabs(x) < eps ? : (x < ? - : ); }
  10. struct Point {
  11. double x, y;
  12.  
  13. Point(const Point& rhs): x(rhs.x), y(rhs.y) { } //拷贝构造函数
  14. Point(double x = 0.0, double y = 0.0): x(x), y(y) { } //构造函数
  15.  
  16. friend istream& operator >> (istream& in, Point& P) { return in >> P.x >> P.y; }
  17. friend ostream& operator << (ostream& out, const Point& P) { return out << P.x << ' ' << P.y; }
  18.  
  19. friend Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
  20. friend Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
  21. friend Vector operator * (const Vector& A, const double& p) { return Vector(A.x*p, A.y*p); }
  22. friend Vector operator / (const Vector& A, const double& p) { return Vector(A.x/p, A.y/p); }
  23. friend bool operator == (const Point& A, const Point& B) { return dcmp(A.x-B.x) == && dcmp(A.y-B.y) == ; }
  24. friend bool operator < (const Point& A, const Point& B) { return dcmp(A.x - B.x)< || (dcmp(A.x - B.x)== && dcmp(A.y - B.y)<); }
  25. void in() { scanf("%lf%lf", &x, &y); }
  26. void out() { printf("%.10f %.10f\n", x, y); }
  27. };
  28.  
  29. template <class T> T sqr(T x) { return x * x;}
  30. double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; } //点积
  31. double Length(const Vector& A){ return sqrt(Dot(A, A)); } //向量长度
  32. double Angle(const Vector& A, const Vector& B) { return acos(Dot(A, B)/Length(A)/Length(B)); } //AB向量夹角
  33. double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; } //AB叉积 有向面积
  34. double Area(const Point& A, const Point& B, const Point& C) { return fabs(Cross(B-A, C-A)); }
  35. //向量旋转 rad正表示逆时针 反之顺时针
  36. Vector Rotate(Vector A,double rad){ return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}
  37. //A不能是0向量
  38. Vector normal(Vector A) { return Point(-A.y, A.x) / Length(A);} //向量A的单位法向量,即A左转90度 以后把长度归归一化
  39. double angle(Vector A) { return atan2(A.y, A.x);} //向量极角 向量A与x轴的夹角
  40. Vector vecunit(Vector A){ return A / Length(A);} //单位向量
  41.  
  42. struct Line {
  43. Point P; //直线上一点
  44. Vector dir; //方向向量(半平面交中该向量左侧表示相应的半平面)
  45. double ang; //极角,即从x正半轴旋转到向量dir所需要的角(弧度)
  46.  
  47. Line() { } //构造函数
  48. Line(const Line& L): P(L.P), dir(L.dir), ang(L.ang) { }
  49. Line(const Point& P, const Vector& dir): P(P), dir(dir) { ang = atan2(dir.y, dir.x); }
  50.  
  51. bool operator < (const Line& L) const { //极角排序
  52. return ang < L.ang;
  53. }
  54. Point point(double t) { return P + dir*t; }
  55. };
  56.  
  57. //直线交点1 P+tv Q+tw
  58. Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
  59. {
  60. Vector u=P-Q;
  61. double t = Cross(w,u)/Cross(v,w);
  62. return P+v*t;
  63. }
  64. //直线交点2
  65. Point GetIntersection(Line a, Line b)
  66. {
  67. Vector u = a.P-b.P;
  68. double t = Cross(b.dir, u) / Cross(a.dir, b.dir);
  69. return a.P + a.dir*t;
  70. }
  71. bool SegmentProperInntersection(Point a1,Point a2,Point b1,Point b2)//线段相交判定
  72. {
  73. double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),
  74. c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
  75. return dcmp(c1)*dcmp(c2)<&&dcmp(c3)*dcmp(c4)<;
  76. }
  77. double DistanceToSegment(Point P,Point A,Point B) //点P到线段AB的距离
  78. {
  79. if(A==B) return Length(P-A);
  80. Vector v1 = B - A,v2 = P - A,v3 = P - B;
  81. if(dcmp(Dot(v1,v2))<) return Length(v2);
  82. else if(dcmp(Dot(v1,v3))>) return Length(v3);
  83. else return fabs(Cross(v1,v2))/Length(v1);
  84. }
  85. Point GetLineProjection(Point P,Point A,Point B) //点P在直线AB上的投影
  86. {
  87. Vector v = B-A;
  88. return A+v*(Dot(v,P-A)/Dot(v,v));
  89. }
  90. bool OnSegment(Point p, Point a1, Point a2) //判断点是否在线段a1a2上 不含端点
  91. {
  92. return dcmp(Cross(a1-p, a2-p)) == && dcmp(Dot(a1-p, a2-p)) < ;
  93. }
  94.  
  95. struct Circle {
  96. Point c; //圆心
  97. double r; //半径
  98.  
  99. Circle() { }
  100. Circle(const Circle& rhs): c(rhs.c), r(rhs.r) { }
  101. Circle(const Point& c, const double& r): c(c), r(r) { }
  102.  
  103. Point point(double ang) const { return Point(c.x + cos(ang)*r, c.y + sin(ang)*r); } //圆心角所对应的点
  104. double area(void) const { return PI * r * r; }
  105. };
  106. bool InCircle(Point x, Circle c)
  107. {
  108. return dcmp(c.r*c.r - Length(c.c - x)*Length(c.c - x)) >= ;
  109. }
  110. //直线与圆的交点
  111. int getLineCircleIntersection(Line L, Circle C, Point* sol) //函数返回交点个数 sol数组存放交点
  112. {
  113. Vector nor = normal(L.dir);
  114. Line pl = Line(C.c, nor);
  115. Point ip = GetIntersection(pl, L);
  116. double dis = Length(ip - C.c);
  117. if (dcmp(dis - C.r) > ) return ;
  118. Point dxy = vecunit(L.dir) * sqrt(C.r*C.r - dis*dis);
  119. int ret = ;
  120. sol[ret] = ip + dxy;
  121. if (OnSegment(sol[ret], L. P, L.point())) ret++;
  122. sol[ret] = ip - dxy;
  123. if (OnSegment(sol[ret], L.P, L.point())) ret++;
  124. return ret;
  125. }
  126. //圆与圆的交点
  127. int getCircleCircleIntersection(Circle C1,Circle C2,vector<Point>& sol)//函数返回交点个数 sol数组存放交点
  128. {
  129. double d=Length(C1.c-C2.c);
  130. if(dcmp(d)==){
  131. if(dcmp(C1.r-C2.r)==) return -;//两圆重合
  132. return ;
  133. }
  134. if(dcmp(C1.r+C2.r-d)<) return ;
  135. if(dcmp(fabs(C1.r-C2.r)-d)>) return ;
  136.  
  137. double a=angle(C2.c-C1.c);
  138. double da=acos((C1.r*C1.r+d*d-C2.r*C2.r)/(*C1.r*d));
  139. Point p1=C1.point(a-da),p2=C1.point(a+da);
  140. sol.push_back(p1);
  141. if(p1==p2) return ;
  142. sol.push_back(p2);
  143. return ;
  144. }
  145. //过点p到圆c的切线
  146. int getTangents(Point p,Circle C,Vector* v)//函数返回条数,v[i]是第i条切线的向量
  147. {
  148. Vector u=C.c-p;
  149. double dist=Length(u);
  150. if(dist<C.r) return ; //点在圆内
  151. else if(dcmp(dist-C.r)==){//p在圆c上,只有一条切线
  152. v[]=Rotate(u,PI/);
  153. return ;
  154. }else{
  155. double ang = asin(C.r/dist);
  156. v[]=Rotate(u,-ang);
  157. v[]=Rotate(u,ang);
  158. return ;
  159. }
  160. }
  161. //两圆的公切线
  162. int getTangents(Circle A,Circle B,Point* a,Point* b)
  163. {
  164. int cnt=;
  165. if(A.r<B.r){swap(A,B);swap(a,b);}
  166. double d2=(A.c.x-B.c.x)*(A.c.x-B.c.x)+(A.c.y-B.c.y)*(A.c.y-B.c.y);
  167. double rdiff=A.r - B.r;
  168. double rsum=A.r + B.r;
  169. if(d2<rdiff*rdiff) return ;//内含
  170.  
  171. double base = atan2(B.c.y-A.c.y,B.c.x-A.c.x);
  172. if(dcmp(d2)==&&dcmp(A.r-B.r)==) return -;//两圆重合,无数条切线
  173. if(dcmp(d2-rdiff*rdiff)==){ //内切,1条切线
  174. a[cnt]=A.point(base);b[cnt]=B.point(base);cnt++;
  175. return ;
  176. }
  177. //有外公切线
  178. double ang=acos((A.r-B.r)/sqrt(d2));
  179. a[cnt] = A.point(base+ang);b[cnt] = B.point(base+ang);cnt++;
  180. a[cnt] = A.point(base-ang);b[cnt] = B.point(base-ang);cnt++;
  181. if(dcmp(d2-rsum*rsum)==){ //一条内公切线
  182. a[cnt]=b[cnt]=A.point(base);cnt++;
  183. }
  184. else if(dcmp(d2-rsum*rsum)>){ //两条内公切线
  185. ang = acos((A.r+B.r)/sqrt(d2));
  186. a[cnt] = A.point(base+ang);b[cnt] = B.point(PI+base+ang);cnt++;
  187. a[cnt] = A.point(base-ang);b[cnt] = B.point(PI+base-ang);cnt++;
  188. }
  189. return cnt;
  190. }
  191. double SegCircleArea(Circle C, Point a, Point b) //线段切割圆
  192. {
  193. double a1 = angle(a - C.c);
  194. double a2 = angle(b - C.c);
  195. double da = fabs(a1 - a2);
  196. if (da > PI) da = PI * 2.0 - da;
  197. return dcmp(Cross(b - C.c, a - C.c)) * da * sqr(C.r) / 2.0;
  198. }
  199.  
  200. double PolyCiclrArea(Circle C, Point *p, int n)//多边形与圆相交面积
  201. {
  202. double ret = 0.0;
  203. Point sol[];
  204. p[n] = p[];
  205. for(int i=;i<n;i++)
  206. {
  207. double t1, t2;
  208. int cnt = getLineCircleIntersection(Line(p[i], p[i+]-p[i]), C, sol);
  209. if (cnt == )
  210. {
  211. if (!InCircle(p[i], C) || !InCircle(p[i+], C)) ret += SegCircleArea(C, p[i], p[i+]);
  212. else ret += Cross(p[i+] - C.c, p[i] - C.c) / 2.0;
  213. }
  214. if (cnt == )
  215. {
  216. if (InCircle(p[i], C) && !InCircle(p[i+], C)) ret += Cross(sol[] - C.c, p[i] - C.c) / 2.0, ret += SegCircleArea(C, sol[], p[i+]);
  217. else ret += SegCircleArea(C, p[i], sol[]), ret += Cross(p[i+] - C.c, sol[] - C.c) / 2.0;
  218. }
  219. if (cnt == )
  220. {
  221. if ((p[i] < p[i + ]) ^ (sol[] < sol[])) swap(sol[], sol[]);
  222. ret += SegCircleArea(C, p[i], sol[]);
  223. ret += Cross(sol[] - C.c, sol[] - C.c) / 2.0;
  224. ret += SegCircleArea(C, sol[], p[i+]);
  225. }
  226. }
  227. return fabs(ret);
  228. }
  229. double PolygonArea(Point *po, int n) //多边形面积
  230. {
  231. double area = 0.0;
  232. for(int i = ; i < n-; i++) {
  233. area += Cross(po[i]-po[], po[i+]-po[]);
  234. }
  235. return area * 0.5;
  236. }
  237. //-----------------------------------------------------------------------------------
  238. Point p[maxn];
  239. int main()
  240. {
  241. double a,w,h;
  242. int n;
  243. cin>>a>>w>>h>>n;
  244. double ang=a/*PI;
  245. double minx=inf,maxx=-1.0;
  246. double miny=inf,maxy=-1.0;
  247. for(int i=;i<n;i++)
  248. {
  249. p[i].in();
  250. p[i]=p[]+Rotate(p[i]-p[],ang);
  251. minx=min(minx,p[i].x);
  252. miny=min(miny,p[i].y);
  253. maxx=max(maxx,p[i].x);
  254. maxy=max(maxy,p[i].y);
  255. }
  256. double dux=w/(maxx-minx);
  257. double duy=h/(maxy-miny);
  258. for(int i=;i<n;i++)
  259. {
  260. p[i].x-=minx;
  261. p[i].y-=miny;
  262. p[i].x*=dux;
  263. p[i].y*=duy;
  264. p[i].out();
  265. }
  266. }

I

题意:给出n个狗的坐标,m个碗的坐标和碗里的数的数量w L(升) , 狗每一秒可以走一个单位长度,狗喝水需要10s ,问S秒内每只狗从自己的位置出发是否全部都能喝完1L水。

题解:如果距离在时限内狗和碗连边,碗拆点就可以了。源点汇点不说了,很简单。

AC代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e4+,mod=1e9+,inf=0x3f3f3f3f;
  4. typedef long long ll;
  5. struct edge
  6. {
  7. int from,to,c,f;
  8. edge(int u,int v,int c,int f):from(u),to(v),c(c),f(f) {}
  9. };
  10. int n,m;
  11. vector<edge> edges;
  12. vector<int> g[maxn];
  13. int d[maxn];//从起点到i的距离
  14. int cur[maxn];//当前弧下标
  15. void init(int N)
  16. {
  17. for(int i=; i<=N; i++) g[i].clear();
  18. edges.clear();
  19. }
  20. void addedge(int from,int to,int c) //加边 支持重边
  21. {
  22. edges.push_back(edge(from,to,c,));
  23. edges.push_back(edge(to,from,,));
  24. int siz=edges.size();
  25. g[from].push_back(siz-);
  26. g[to].push_back(siz-);
  27. }
  28. int bfs(int s,int t) //构造一次层次图
  29. {
  30. memset(d,-,sizeof(d));
  31. queue<int> q;
  32. q.push(s);
  33. d[s]=;
  34. while(!q.empty())
  35. {
  36. int x=q.front();q.pop();
  37. for(int i=;i<g[x].size();i++)
  38. {
  39. edge &e=edges[g[x][i]];
  40. if(d[e.to]<&&e.f<e.c) //d[e.to]=-1表示没访问过
  41. {
  42. d[e.to]=d[x]+;
  43. q.push(e.to);
  44. }
  45. }
  46. }
  47. return d[t];
  48. }
  49. int dfs(int x,int a,int t) // a表示x点能接收的量
  50. {
  51. if(x==t||a==)return a;
  52. int flow=,f;//flow总的增量 f一条增广路的增量
  53. for(int &i=cur[x];i<g[x].size();i++)//cur[i] &引用修改其值 从上次考虑的弧
  54. {
  55. edge &e=edges[g[x][i]];
  56. if(d[x]+==d[e.to]&&(f=dfs(e.to,min(a,e.c-e.f),t))>) //按照层次图增广 满足容量限制
  57. {
  58. e.f+=f;
  59. edges[g[x][i]^].f-=f; //修改流量
  60. flow+=f;
  61. a-=f;
  62. if(a==) break;
  63. }
  64. }
  65. return flow;
  66. }
  67. int maxflow(int s,int t)
  68. {
  69. int flow=;
  70. while(bfs(s,t)!=-) //等于-1代表构造层次图失败 结束
  71. {
  72. memset(cur,,sizeof(cur));
  73. flow+=dfs(s,inf,t);
  74. }
  75. return flow;
  76. }
  77. struct node
  78. {
  79. ll first,second;
  80. }dog[maxn],bowl[maxn];
  81. int num[maxn];
  82. ll s;
  83. int main()
  84. {
  85. while(scanf("%d%d%lld",&n,&m,&s)!=EOF)
  86. {
  87. init(n+*m+);
  88. for(int i=;i<=n;i++)
  89. scanf("%lld%lld",&dog[i].first,&dog[i].second);
  90. for(int i=;i<=m;i++)
  91. scanf("%lld%lld%d",&bowl[i].first,&bowl[i].second,&num[i]);
  92. for(int i=;i<=n;i++)
  93. {
  94. addedge(,i,);
  95. for(int j=;j<=m;j++)
  96. {
  97. if(sqrt(pow(abs(dog[i].first-bowl[j].first),)+pow(abs(dog[i].second-bowl[j].second),))+<=s)
  98. addedge(i,n+j,);
  99. }
  100. }
  101. for(int j=;j<=m;j++)
  102. addedge(n+j,n+m+j,num[j]),
  103. addedge(n+m+j,n+*m+,inf);
  104. if(maxflow(,n+m*+)==n)
  105. printf("YES\n");
  106. else
  107. printf("NO\n");
  108. }
  109. }

Gym 101917 E 简单计算几何,I 最大流的更多相关文章

  1. 简单CSS定位瀑布流实现方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 简单聊聊Storm的流分组策略

    简单聊聊Storm的流分组策略 首先我要强调的是,Storm的分组策略对结果有着直接的影响,不同的分组的结果一定是不一样的.其次,不同的分组策略对资源的利用也是有着非常大的不同,本文主要讲一讲loca ...

  3. ●POJ 1556 The Doors(简单计算几何+最短路)

    ●赘述题目 10*10的房间内,有竖着的一些墙(不超过18个).问从点(0,5)到(10,5)的最短路. 按照输入样例,输入的连续5个数,x,y1,y2,y3,y4,表示(x,0--y1),(x,y2 ...

  4. 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...

  5. Gym - 102346G Getting Confidence 最小费用最大流

    Gym - 102346GGetting Confidence 题意:n*n的格子,每个格子上有一个数,要求每行每列都只能拿一个数,使得乘积最大,然后输出每列选择的是第几行的数. 如果是加法的话,那么 ...

  6. 2018.07.03 BZOJ 1007: [HNOI2008]水平可见直线(简单计算几何)

    1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MB Description 在xoy直角坐标平面上有n条直线L1,L2,-Ln, ...

  7. HDU2948Geometry Darts(简单计算几何)

    题目大意就是说两个人掷飞镖,飞镖在所给定的图形内就记一分,现在给定N个图形(圆.三角形和矩形),问每一次比赛(没人分别掷三次)谁赢. #include <map> #include < ...

  8. Gym 101606L - Lounge Lizards - [计算几何+LIS]

    题目链接:https://codeforces.com/gym/101606/problem/L 题解: 在同一条线上的所有蜥蜴,他们的斜率都是相通的,换句话说可以直接通过斜率将蜥蜴分组. 每一组即代 ...

  9. 两个简单的API限流实现方案

    1, Ngnix限流 Nginx在架构中起到请求转发与负载均衡器的作用.外部req首先到Nginx监听的80端口,然后Nginx将req交给到监听8080端口的APP服务器处理.处理结果再经由Ngin ...

随机推荐

  1. python日记整理

    都是自己的学习总结,要是总结的有问题大佬麻烦评价一下我好修改,谢谢 python插件插件+pycharm基本用法+markdown文本编写+jupyter notebook的基本操作汇总 一.计算机基 ...

  2. [译]The Python Tutorial#4. More Control Flow Tools

    [译]The Python Tutorial#More Control Flow Tools 除了刚才介绍的while语句之外,Python也从其他语言借鉴了其他流程控制语句,并做了相应改变. 4.1 ...

  3. 解决oh-my-zsh卡顿问题

    git config --global oh-my-zsh.hide-status 1

  4. drf 视图功能

    视图 drf提供的视图功能 自己的第一次封装 #一个功能写成一个类,方便组合,只要继承它就可以有这个功能 #将功能都写在一个类中,可控性就会变差 from book.myserializers imp ...

  5. python能干什么?

    python能干什么? 网络爬虫 爬虫,指的是从互联网采集数据的程序脚本 . 爬天爬地爬空气 ,无聊的时候爬一爬吃鸡数据.b站评论,能得出很多有意思的结论.知乎有个很有意思的问题——"利用爬 ...

  6. Python中的属性访问与描述符

    Python中的属性访问与描述符 请给作者点赞--> 原文链接 在Python中,对于一个对象的属性访问,我们一般采用的是点(.)属性运算符进行操作.例如,有一个类实例对象foo,它有一个nam ...

  7. BZOJ 2465: [中山市选2009]小球

    难度在于读题 #include<cstdio> #include<algorithm> using namespace std; int a[1000005]; struct ...

  8. C++ 获取网页源码码的操作

    #include <stdio.h>#include <windows.h>#include <wininet.h>#pragma comment(lib,&quo ...

  9. uiautomatorviewer打不开

    uiautomatorviewer打不开: 因为之前我下载的jdk版本为10,后来将jdk版本改为8之后就可以打开了.

  10. ef添加数据时出错 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException”类型的异常

    找半天才找到 ef添加数据时出错原因:数据库表中没有主键 ,就算表中有自增列 Added方法也会报错: -        this._db.SaveChanges() “this._db.SaveCh ...