`
tulunta
  • 浏览: 360231 次
文章分类
社区版块
存档分类
最新评论

Enumerate the Triangles&&http://cdn.ac.nbutoj.com/Contest/view/id/14/problem/E.xhtml

 
阅读更多
  • 问题描述
  • 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;
    }
    


  • 分享到:
    评论

    相关推荐

      sqlmap (懂的入)

      * 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 ...

      强大的国外注入工具-darkMySQLi.py

      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,...

      Android代码-HTTP Tools

      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. ...

      gvim常用插件及其配置文件配置(下载解压即可使用)

      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 ...

      Intel_ACPI_Low_Power_S0_Idle.pdf

      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: ...

      DriverStoreExplorer.v0.8.4.2查看windows驱动程序

      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. ...

      测量程序编制 - python 18数据类型:序列(函数enumerate) .pptx

      序 列(函数enumerate)enumerateenumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中语法:enumerate(sequence, [start=0])参数:...

      Qt Linux版USB-HID通讯范例

      Qt Linux版USB-HID通讯范例,原文地址:https://blog.csdn.net/u010875635/article/details/73277779

      Python语言基础:创建线程.pptx

      程序只能从上到下,... print('所有线程信息:%s'%threading.enumerate()) def init(): thread = threading.Thread(target=thread_job) #定义线程 thread.start() #启动线程 if __name__ == '__main__': init()

      BobBuilder_app

      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错误-device descriptor read/64, error -62

      彻底解决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

      fine_tuning_data.zip 可直接用bert进行微调的中文情绪数据

      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 = ...

      Enumerate Site-crx插件

      键入s和一个空格以激活Enumerate-Site 2.键入您的搜索词 3.使用箭头或鼠标选择搜索结果之一,以直接转到该页面。有一个扩展选项可删除“转到完整的搜索结果”条目,从而使另外一个搜索结果可见 (请注意,不幸的是,...

      Senfore_DragDrop_v4.1

      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 ...

      dropcam:Dropcam Python API

      &gt;&gt;&gt; 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; ...

      基于python实现贪心算法、蛮力法、动态规划法解决分数背包问题和0-1背包问题源码+项目说明.zip

      value = list(enumerate(danwei_v)) #enumerate()函数将物品序号与其对应单位价值组合为一组数对 value.sort(key=lambda a: a[1], reverse=True) #按物品单位价值降序排序 while c &gt; 0: for i in range(n): if ...

      dotCMSTokenGenerator:PoC JWT令牌生成器,由TimoMüller编写

      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 &lt;arg&gt; enumerate ...

      itertools-deno:用于Deno的Python itertools和more-itertools的TypeScript端口

      enumerate ( [ "hello" , "world" ] ) ] ) ;// [0, 'hello'], [1, 'world'] 该模块提供了从Python的内置函数, , 移植的更多函数。 换句话说,所有功能由原始。 有关更多详细信息,请参见。执照该代码遵循以编写的...

    Global site tag (gtag.js) - Google Analytics