zoukankan      html  css  js  c++  java
  • FZOJ2110: Star

    Problem Description

    Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.

    Input

    The first line of the input contains an integer T (T≤10), indicating the number of test cases.

    For each test case:

    The first line contains one integer n (1≤n≤100), the number of stars.

    The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.

    Output

    For each test case, output an integer indicating the total number of different acute triangles.

    Sample Input

    1
    3
    0 0
    10 0
    5 1000

    Sample Output

    1

    题意:每个样例给出n,然后n个坐标,求这些点能组成多少个锐角三角形

    思路:只要知道锐角三角形三边的关系a^2+b^2>c^2即可

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    
    int main()
    {
    	double a[2][105],x,y,z;
    	int i,j,k,ans,n,t,flag1,flag2,flag3;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d",&n);
    		for(i = 0;i<n;i++)
    			scanf("%lf%lf",&a[0][i],&a[1][i]);
    		ans = 0;
    		for(i = 0;i<n-2;i++)
    		{
    			for(j = i+1;j<n-1;j++)
    			{
    				for(k = j+1;k<n;k++)
    				{
    					flag1 = flag2 = flag3 = 0;
    					x = sqrt((a[0][i]-a[0][j])*(a[0][i]-a[0][j])+(a[1][i]-a[1][j])*(a[1][i]-a[1][j]));
    					y = sqrt((a[0][i]-a[0][k])*(a[0][i]-a[0][k])+(a[1][i]-a[1][k])*(a[1][i]-a[1][k]));
    					z = sqrt((a[0][k]-a[0][j])*(a[0][k]-a[0][j])+(a[1][k]-a[1][j])*(a[1][k]-a[1][j]));
    					if(x*x+y*y>z*z)
    						flag1 = 1;
    					if(y*y+z*z>x*x)
    						flag2 = 1;
    					if(x*x+z*z>y*y)
    						flag3 = 1;
    					if(flag1 && flag2 && flag3)
    						ans++;
    				}
    			}
    		}
    		printf("%d
    ",ans);
    	}
    
    	return 0;
    }
    


     

  • 相关阅读:
    一些命令
    DB-5:使用PowerDesigner连接数据库并生成ER图
    [原创]OpenEuler20.03安装配置PostgreSQL13.4详细图文版
    oss 视频转码
    java lambda groupby 的map顺序问题
    Springboot得到RabbitMQ队列消息的数量
    Rabbitmq 定时任务 (代码实现)
    Rabbitmq 定时任务
    Mac navicat 15
    Mac 重置 idea
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3244057.html
Copyright © 2011-2022 走看看