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$ ...
随机推荐
- JavaScript函数作用域与对象以及实用技巧
1. JS作用域 1.1 全局作用域和局部作用域 函数外面声明的就是 全局作用域 函数内是局部作用域 全局变量可以直接在函数内修改和使用 变量,使用var是声明,没有var是使用变量. 如果在函数内使 ...
- linux for 循环的小应用
[root@localhost ~]# mkdir -pv /home/data{1..5} # 创建多个目录 以下两种方法类似. for i in {1..5};do echo "&l ...
- Python学习过程笔记整理(三)
函数 -函数使用 -函数需要先定义,定义不会执行函数 -使用函数,俗称调用 -定义函数 -格式:def 函数名称(参数=默认值):,函数名称不能用大驼峰,参数可以没有 -调用函数 -格式:函数名(参数 ...
- Vue2.0原理-模板解析
下面这段代码,vue内部做了什么操作?我去源码里面找找看 new Vue({ el: '#app' }) 入口 vue 的入口文件在 src/core/instance/index.js, 里面一进来 ...
- RabbitMQ入门:远程过程调用(RPC)
假如我们想要调用远程的一个方法或函数并等待执行结果,也就是我们通常说的远程过程调用(Remote Procedure Call).怎么办? 今天我们就用RabbitMQ来实现一个简单的RPC系统:客户 ...
- RabbitMQ入门:工作队列(Work Queue)
在上一篇博客<RabbitMQ入门:Hello RabbitMQ 代码实例>中,我们通过指定的队列发送和接收消息,代码还算是比较简单的. 假设有这一些比较耗时的任务,按照上一次的那种方式, ...
- C++ 类 析构函数
一.析构函数的定义 析构函数为成员函数的一种,名字与类名相同,在前面加‘~’没有参数和返回值在C++中“~”是位取反运算符.一个类最多只能有一个析构函数.析构函数不返回任何值,没有函数类型,也没有函数 ...
- Notes of Daily Scrum Meeting(11.8)
Notes of Daily Scrum Meeting(11.8) 预备中开始写代码的第一天,因为大家对Android编程的熟悉程度还是不够,所以工程进行的非常缓慢,有四名队员 开始编写自己的任务, ...
- BugPhobia展示篇章:学霸在线系统Alpha阶段展示
0x00:序言 1 universe, 9 planets, 204 countries,809 islands, 7 seas, and i had the privilege to meet yo ...
- 《Spring 2之站立会议3》
<Spring 2之站立会议3> 昨天,查找了本机的端口号,并对代码作进一步的了解. 今天,对我们项目的基本框架进行了了解,即主界面和各个分界面的基本架构: 遇到的问题,虽然了解了基本框架 ...