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$ ...
随机推荐
- Famous框架系列一:famous/core/Surface
famous/core/Surface 既然是Famous的第一篇文章,就先给Famous打个广告:http://periodic.famo.us Famous12年的作品,点击右下角Fun thi ...
- .net mvc中session的锁机制
今天遇到个奇怪的问题, 一个秒杀商品系统, 大量秒杀请求进来, 到了action居然是单线程执行! 这样产生的效果就是“这个系统好慢啊!!”. 可是我没有加lock,为什么会变成单线程执行呢? 找资料 ...
- Sklearn环境搭建与常用包
开发环境搭建 直接安装Anaconda IPython IPython是公认的现代科学计算中最重要的Python工具之一.它是一个加强版的Python交互命令行工具,有以下几个明显的特点: 1. 可以 ...
- node.js学习笔记——前序
一.什么是node.js 简单的说 Node.js 就是运行在服务端的 JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一 ...
- [翻译] Python 3.5中async/await的工作机制
Python 3.5中async/await的工作机制 多处翻译出于自己理解,如有疑惑请参考原文 原文链接 身为Python核心开发组的成员,我对于这门语言的各种细节充满好奇.尽管我很清楚自己不可能对 ...
- 解决了一个困扰我近一年的vim显示中文乱码的问题
今天解决了vi命令打开日志文件中文总是显示乱码的问题.由于项目组中的日志包含一些特殊字符,所以使用vim打开日志文件时总是不能正确识别出文件字符编码.此时用:set fileencoding命令可以看 ...
- java-POI处理excel文件方法
处理excel文件的开源库有很多,常见的POI.jxls..... 重点分析下POI处理excel的方法: 1.写文件 // 按照行优先进行数据表格的初始化 public static void cr ...
- python基础学习笔记(一)
最好有点c++基础来看,,每天都更新一篇吧 这一篇是一些基础东西 1.运算符2.变量3.基本输入输出4.字符串5.列表6.元组7.字典8.集合9.简单的说下循环啥的 1.运算符 特别的 a / b:为 ...
- IDA入门笔记
题目来源: 南邮CTF :: RE :: Hello,RE(应该是) XDUCTF :: ??? :: ????????(不知道不知道不知道) 总而言之我会在百度网盘再上传一份: >>百度 ...
- Python字典 (dict)
作者博文地址:http://www.cnblogs.com/spiritman/ 字典是Python语言中唯一的映射类型.字典对象是可变的,它是一个容器类型,支持异构.任意嵌套. 创建字典 语法:{k ...