问题描述
Little E is doing geometry works. After drawing a lot of points on a plane, he want to enumerate all the triangles which
the vertexes are three of the points to find out the one with minimum perimeter. Your task is to implement his work.
输入
The input contains several test cases. The first line of input contains only one integer denoting the number of test cases.
The first line of each test cases contains a single integer N, denoting the number of points. (3 <= N <= 1000)
Next N lines, each line contains two integer X and Y, denoting the coordinates of a point. (0 <= X, Y <= 1000)
输出
For each test cases, output the minimum perimeter, if no triangles exist, output "No Solution".
样例输入
2
3
0 0
1 1
2 2
4
0 0
0 2
2 1
1 1
样例输出
Case 1: No Solution
Case 2: 4.650
题意:给你一些点,让你求这些点组成的最小三角形的面积,如果不存在则输出No sluation,
思路:常规方法,暴力枚举,但是一定要注意剪枝,这里排序的目的就是为了剪枝,,,囧,,
AC代码:
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 1001
using namespace std;
typedef struct str
{
int x;
int y;
}Node;
Node s[N];
int Scan()
{
int num = 0 , ch ;
while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
{
if( ch == EOF ) return 1 << 30 ;
}
num = ch - '0' ;
while( ( ch = getchar() ) >= '0' && ch <= '9' )
num = num * 10 + ( ch - '0' ) ;
return num;
}
bool cmp(Node a,Node b)
{return ((a.x<b.x)||(a.x==b.x&&a.y<b.y));}
double distan(Node a,Node b)
{return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
bool line(Node a,Node b,Node c)判断三点是不是共线
{
a.x-=c.x;
a.y-=c.y;
b.x-=c.x;
b.y-=c.y;
return a.x*b.y==a.y*b.x;
}
int main()
{
int T=Scan();
for(int xx=1;xx<=T;++xx)
{
int n=Scan();
for(int i=0;i!=n;++i)
s[i].x=Scan(),s[i].y=Scan();
sort(s,s+n,cmp);
double ans=1e10;
for(int i=0;i!=n;++i)
{
for(int j=i+1;j!=n;++j)
{
if(2*abs(s[j].x-s[i].x)>ans) break;
if(2*distan(s[j],s[i])>ans) continue;
for(int k=j+1;k!=n;++k)
{
if(line(s[k],s[j],s[i])) continue;
if(2*abs(s[k].x-s[i].x)>ans) break;
double res=distan(s[i],s[j])+distan(s[i],s[k])+distan(s[j],s[k]);
if(res<ans) ans=res;
}
}
}
if(ans<1e10) printf("Case %d: %.3lf\n",xx,ans);
else printf("Case %d: No Solution\n",xx);
}return 0;
}
分享到:
相关推荐
* It is possible to view the Estimated time of arrival for each query output, updated in real time while performing the SQL injection attack; * Support to increase the verbosity level of output ...
darkc0de:darkMySQLi rsauron$ ./darkMySQLi.py -u "http://www.rayner.com/products.php?id=22/**/AND/**/1=2/**/UNION/**/SELECT/**/1,darkc0de,3,4, 5,6,7,8,9,10" --dump -D db2889_rayner_en -T auth -C name,...
Sublist3r is a python tool designed to enumerate subdomains of websites using OSINT. It helps penetration testers and bug hunters collect and gather subdomains for the domain they are targeting. ...
arabic ccaption enumerate footmisc ifthen multicol plates url array changebar eqlist geometry inputenc newalg polski verbatim .vim/ftplugin/latex-suite/templates: article.tex IEEEtran.tex report.tex ...
To enumerate platform Low Power Idle states, Intel platforms are using “Low Power Idle Table” (LPIT). More details about this table can be downloaded from: ...
Enumerate / List all the packages staged in the current driver store. Export the list as CSV. Add a driver package to the driver store (called staging) Install & Add a driver package to the store. ...
序 列(函数enumerate)enumerateenumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中语法:enumerate(sequence, [start=0])参数:...
Qt Linux版USB-HID通讯范例,原文地址:https://blog.csdn.net/u010875635/article/details/73277779
程序只能从上到下,... print('所有线程信息:%s'%threading.enumerate()) def init(): thread = threading.Thread(target=thread_job) #定义线程 thread.start() #启动线程 if __name__ == '__main__': init()
In the event of page getting full and reaching the PageItemCount, MGIndex will sort the keys in the page's dictionary and split the data in two pages ( similar to a b+tree split) and update the page ...
彻底解决usb错误 一插上usb就报如下错误: / # usb 1-1: new full speed USB device using s3c2410-ohci and address 2 usb 1-1: device descriptor read/64,...hub 1-0:1.0: unable to enumerate USB device on port 1
for (i, line) in enumerate(lines): if i == 0: continue guid = "%s-%s" % (set_type, i) if set_type == "test": label = "0" text_a = tokenization.convert_to_unicode(line[0]) else: label = ...
键入s和一个空格以激活Enumerate-Site 2.键入您的搜索词 3.使用箭头或鼠标选择搜索结果之一,以直接转到该页面。有一个扩展选项可删除“转到完整的搜索结果”条目,从而使另外一个搜索结果可见 (请注意,不幸的是,...
work around will fix the problem: In the project options of *all* projects which uses these components, add the following conditional define: NO_WIN32_LEAN_AND_MEAN The define *must* be made in ...
>>> for i, cam in enumerate(d.cameras()): ... cam.save_image("camera.%d.jpg" % i) 安装 易于安装 $ pip install dropcam 或从来源 $ git clone https://github.com/rsgalloway/dropcam.git $ cd dropcam $ ...
// Enumerate through all devices in Set. DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData;);i++) { DWORD DataT; //LPTSTR buffer = NULL; ...
value = list(enumerate(danwei_v)) #enumerate()函数将物品序号与其对应单位价值组合为一组数对 value.sort(key=lambda a: a[1], reverse=True) #按物品单位价值降序排序 while c > 0: for i in range(n): if ...
java -jar ./dotCMSTokenGenerator-0.0.1-shaded.jar ----- dotCMS TokenGenerator PoC by MOGWAI LABS GmbH (https://mogwailabs.de) ----- usage: generate_dotCMS_JWT.jar -e,--enumerate <arg> enumerate ...
enumerate ( [ "hello" , "world" ] ) ] ) ;// [0, 'hello'], [1, 'world'] 该模块提供了从Python的内置函数, , 移植的更多函数。 换句话说,所有功能由原始。 有关更多详细信息,请参见。执照该代码遵循以编写的...