CodeForces 682 E.Alyona and Triangles(计算几何)
来源:互联网 发布:品茗网络计划教程 编辑:程序博客网 时间:2024/05/22 01:57
Description
给出n个整点,其中任意三个点构成三角形的面积不超过S,要求构造一个面积不超过4S的大三角形包含这n个点
Input
第一行两个整数n和S,之后n行每行两个整数x,y表示该点横纵坐标
(3<=n<=5000,1<=S<=1e18,-1e8<=x,y<=1e8)
Output
输出大三角形三点坐标
Sample Input
4 1
0 0
1 0
0 1
1 1
Sample Output
-1 0
2 0
0 2
Solution
先任选三个点构成一个三角形然后迭代出这n个点中面积最大的三角形,然后把这个三角形三个顶点分别沿对边中点对称过去,三个对称点构成的大三角形即为答案
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 5555int n,x[maxn],y[maxn];ll S;ll get_s(int i,int j,int k){ int x1=x[k]-x[i],y1=y[k]-y[i],x2=x[k]-x[j],y2=y[k]-y[j]; return abs(1ll*x1*y2-1ll*x2*y1);} int main(){ while(~scanf("%d%I64d",&n,&S)) { for(int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]); int a=1,b=2,c=3,flag=1; ll s=get_s(1,2,3); while(flag) { flag=0; for(int i=1;i<=n;i++) { if(s<get_s(i,b,c))s=get_s(i,b,c),a=i,flag=1; if(s<get_s(a,i,c))s=get_s(a,i,c),b=i,flag=1; if(s<get_s(a,b,i))s=get_s(a,b,i),c=i,flag=1; } } printf("%d %d\n",x[a]+x[b]-x[c],y[a]+y[b]-y[c]); printf("%d %d\n",x[a]+x[c]-x[b],y[a]+y[c]-y[b]); printf("%d %d\n",x[b]+x[c]-x[a],y[b]+y[c]-y[a]); } return 0;}
阅读全文
0 0
- CodeForces 682 E.Alyona and Triangles(计算几何)
- Cf #358 (Div. 2) E Alyona and Triangles (682E)
- Codeforces Round #358 (Div. 2) E. Alyona and Triangles (找面积最大三角形)
- Codeforces 682E 计算几何
- codeforces 13D. Triangles(计算几何 dp)
- Codeforces Round #381 (Div. 2) E. Alyona and towers
- CodeForces 682C - Alyona and the Tree(dfs)
- codeforces 682C Alyona and the Tree(DFS)
- Codeforces-682A:Alyona and Numbers(水题)
- 1659. Regular Triangles(计算几何)
- FZU 2270 Two Triangles (计算几何)
- Regular Triangles(计算几何)
- Codeforces Beta Round #13 D —— Triangles 计算几何
- CodeForces - 552D Vanya and Triangles (数学几何求三角形个数)水
- CodeForces 682A Alyona and Numbers
- CodeForces 682B Alyona and Mex
- Codeforces 682C. Alyona and the Tree
- codeforces 682C. Alyona and the Tree
- 对TA 镜像文件的加密
- 洛谷1028
- dubbo下的异常统一处理
- 四叉树与八叉树
- Windows 10 1703官方原版镜像(Build 15063.0)
- CodeForces 682 E.Alyona and Triangles(计算几何)
- 查找单链表倒数第K个节点和以及逆置单链表
- 使用Jmeter压力测试
- 看过来:种子轮…A轮?Pre-A?IPO?融资轮次,傻傻分不清楚
- ios报ASSERT FAILED ON LUA EXECUTE: key not found : <integer/real>的问题
- 洛谷 P1027 Car的旅行路线
- git使用笔记3(在github上创建远程仓库)
- 广播
- 使用类的属性保存数据库连接参数