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$ ...
随机推荐
- 并发系列(三)-----volatile
一 简介 volatile关键字是轻量级的synchronized,volatile在并发编程中保证共享变量的可见性,当一个线程修改被volatile修饰的共享变量时,另外一个线程就能读到这个修改的值 ...
- windows系统下构建Jenkins持续集成
环境准备 windows10+tomcat+python3.x(安装方法自行百度) 安装Jenkins 从https://jenkins.io/download/ 下载war包 将war包放到tomc ...
- Linux入门基础(七):Linux软件管理基础
源代码形式 绝大多数开源软件都是直接以源代码形式发布 源代码一般会被打包成tar.gz的归档压缩文件 程序源代码需要编译成为二进制形式之后才能够运行 源代码基本编译流程 : ./configure 检 ...
- VM虚拟机安装CentOS 7.0添加jdk环境
虚拟机注册码 5A02H-AU243-TZJ49-GTC7K-3C61N 安装centos系统,网络类型选择桥接网络安装完成后vi /etc/sysconfig/network-scripts/ifc ...
- Xshell6远程访问linux及Xftp6远程针对linux系统中文件操作(附图文详解)
1.首先我们需要先做好前期准备工作,需要到XManager6官网上将Xshell及Xftp下载并安装,安装过程一直下一步就好了.这里是其官网:http://www.xshellcn.com/.安装完成 ...
- vue 自定义全局按键修饰符
在监听键盘事件时,我们经常需要检查常见的键值.Vue 允许为 v-on 在监听键盘事件时添加按键修饰符: JS部分: Vue.config.keyCodes = { f2:113, } var app ...
- 使用Zabbix的SNMP trap监控类型监控设备的一个例子
本文以监控绿盟设备为例. 1.登录被监控的设备的管理系统,配置snmptrap地址指向zabbix服务器或代理服务器. snmptrap地址也叫陷阱. 2.验证是否能在zabbix服务器或代理服务器上 ...
- HTML学习1-Dom之事件绑定
事件: 1.注册事件 a. <div onxxxx=””></div> b. document .onxxxx= function() //找到这个标签 2.this,触发 ...
- linux安装nginx并配置负载均衡
linux上安装nginx比较简单: 前提是需要有gcc或者g++ 1.yum需要的依赖 yum -y install openssl openssl-devel 2.解压pcre库.zlib库 ...
- 第二次作业(homework-02)成绩公布
学位后三位和对应成绩: 057 0008 4011 4012 7014 5015 5017 6018 0019 0026 2027 7036 0038 7.5046 7048 6.5051 0061 ...