topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement |
|||||||||||||
|
You are given the ints perimeter and area. Your task is to find a triangle with the following properties:
If there are multiple solutions, you may choose any of them. Return a vector <int> with six elements: {x1, y1, x2, y2, x3, y3}, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of the vertices of your triangle. If there is no solution, return an empty vector <int> instead. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
| - | area will be between 1 and 1,000,000, inclusive. | ||||||||||||
| - | perimeter will be between 1 and 1000, inclusive. | ||||||||||||
Examples |
|||||||||||||
| 0) | |||||||||||||
|
|||||||||||||
| 1) | |||||||||||||
|
|||||||||||||
| 2) | |||||||||||||
|
|||||||||||||
| 3) | |||||||||||||
|
|||||||||||||
| 4) | |||||||||||||
|
|||||||||||||
| 5) | |||||||||||||
|
|||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> cnt[];
class FindThePerfectTriangle
{
public:
vector <int> constructTriangle(int area, int perimeter) {
int c;
for (int i = ; i <= ; ++i)cnt[i*i].emplace_back(i, );
for (int i = ; i <= ; ++i) {
for (int j = ; j<i&&j*j+i*i<=; ++j) {
if (cnt[i*i + j*j].empty())continue;
cnt[i*i + j*j].emplace_back(i, j);
}
}
for (int a = ; a <= && a + < perimeter; a++) {
for (int b = ; b <= && a + b < perimeter&&b <= a; b++) {
c = perimeter - a - b;
if (a < c || b < c || a >= (b + c))continue;
//用海拉公式的变形来验证面积正确
long long p = perimeter;
long long s = p*(p - * a)*(p - * b)*(p - * c);
if (s == (long long)() * area*area) {
int A = a*a, B = b*b;
//枚举A和B的拆分方式
for (int i = ; i<cnt[A].size(); i++)
for (int j = ; j<cnt[B].size(); j++) {
int x1 = cnt[A][i].first, y1 = cnt[A][i].second;
int x2 = cnt[B][j].first, y2 = cnt[B][j].second;
int xx, yy;
for(int s1=-;s1<=;s1+=)
for(int s2=-;s2<=;s2+=){
xx = x1 - s1*x2;
yy = y1 - s2*y2;
if(xx*xx+yy*yy==c*c){
vector<int>res;
res.push_back(); res.push_back();
res.push_back(+x1); res.push_back(+y1);
res.push_back(+s1*x2); res.push_back(+s2*y2);
return res;
}
xx = x1 - s1*y2;
yy = y1 - s2*x2;
if (xx*xx + yy*yy == c*c){
vector<int>res;
res.push_back(); res.push_back();
res.push_back( + x1); res.push_back( + y1);
res.push_back( + s1*y2); res.push_back( + s2*x2);
return res;
}
}
} }
}
}
vector<int>res;
return res;
}
};
topcoder srm 738 div1 FindThePerfectTriangle(枚举)的更多相关文章
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
- topcoder srm 640 div1
problem1 link 首先使用两个端点颜色不同的边进行连通.答案是$n-1-m$.其中$m$是联通分量的个数. problem2 link 首先构造一个最小割的模型.左边的$n_{1}$个点与源 ...
- topcoder srm 635 div1
problem1 link 首先枚举长度$L$.然后计算每一段长度$L$的差值最大公约数,然后差值除以最大公约数的结果可以作为当前段的关键字.然后不同段就可以比较他们的关键字,一样就是可以转化的. p ...
- topcoder srm 630 div1 (2-SAT and SCC template)
problem1 link 首先计算任意两点的距离.然后枚举选出的集合中的两个点,判断其他点是否可以即可. problem2 link 假设字符串为$s$,长度为$n$.那么对于$SA$中的两个排名$ ...
- topcoder srm 600 div1
problem1 link 首先,如果一个数字的某一位是1但是$goal$的这一位不是1,那么这个数字是不用管它的.那么对于剩下的数字,只需要统计在$goal$为1的位上,这些数字对应位上也是1的数字 ...
- topcoder srm 585 div1
problem1 link 最优的策略就是从最低下一层开始,每两层的三个节点的子树都可以用一次遍历覆盖. problem2 link 从大到小依次放置每一种数字,并记录已经放置的数字一共有多少个$m$ ...
随机推荐
- docker 下载安装与配置
# mac离线安装dockerhttps://download.docker.com/mac/stable/24312/Docker.dmg # windows离线安装dockerhttp://mir ...
- 打包一个传统的ASP.NET web app作为Docker镜像
(1)针对NerdDinner应用的Dockerfile内容如下 PS E:\DockeronWindows\Chapter02\ch02-nerd-dinner> cat .\Dockerfi ...
- 6.openldap客户端安装
作者:yaoyao 1.账号登录系统流程讲解 当在客户端输入账号登录系统时.系统根据/etc/nsswitch.conf配置文件获取账号查找顺序,然后在根据pam配置文件调用相关模块,对账号/etc/ ...
- cp命令详解
基础命令学习目录首页 http://man.linuxde.net/cp 如果把一个文件复制到一个目标文件中,而目标文件已经存在,那么,该目标文件的内容将被破坏.此命令中所有参数既可以是绝对路径名,也 ...
- Win7-64位PowerDesigner下MySQLODBC驱动问题
操作系统:win7-64位,PowerDesigner15.1(以下简称PD), MYSQL-ODBC-64驱动.安装完MYSQL-ODBC-64却找不到相关驱动,用PD反导数据库,却找不到Mysql ...
- vim 多个文件切换 :b 命令
MiniBufExplorer插件的使用 博客分类: vim vimMiniBufExplorer 快速浏览和操作Buffer -- 插件: MiniBufExplorer 下载地址 [http:// ...
- final文案+美工展示
作业要求:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1438 团队介绍:thunder 组成员及各位博客地址: 1.王航:htt ...
- t团队项目计划
团队的backlog: .用户登录网站后,可以选择是买或者卖, (1)买 点击链接,可以分类浏览商品信息,也可以按价钱筛选 (2)卖 点击链接,选择要挂出的商品种类,填写信息(名称.价格.数量等)接着 ...
- KMP算法之next数组的求解思路
2.next数组的求解思路 本部分内容转自:http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algo ...
- Go Going软件需求规格说明书
1.目标是什么,目标不包括什么? 我们软件的目标是让大学生走出校园,用最小的花费到更多的地方去,开阔视野,读万卷书再行万里路. 目标暂且不包括外校学生 2.用户和典型场景是什么? 用户:在校大学生 典 ...