zoukankan      html  css  js  c++  java
  • ACM: FZU 2110 Star

     FZU 2110  Star
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    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

    求锐角三角形的个数;

    数学结论 : 锐角三角形 任意边满足 a^2<b^2+c^2 ;

    AC代码:

    #include"algorithm"
    #include"iostream"
    #include"cstring"
    #include"cstdlib"
    #include"cstdio"
    #include"string"
    #include"vector"
    #include"stack"
    #include"queue"
    #include"cmath"
    #include"map"
    using namespace std;
    typedef long long LL ;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define FK(x) cout<<"["<<x<<"]
    "
    #define memset(x,y) memset(x,y,sizeof(x))
    #define memcpy(x,y) memcpy(x,y,sizeof(x))
    #define bigfor(T)  for(int qq=1;qq<= T ;qq++)
    
    struct Star {
    	LL x;
    	LL y;
    } st[200];
    
    bool cmp(LL a,LL b) {
    	return a>b;
    }
    
    bool check(int i,int j,int k) {
    	LL s[3];
    	s[0]=(st[i].x-st[j].x)*(st[i].x-st[j].x)+(st[i].y-st[j].y)*(st[i].y-st[j].y);
    	s[1]=(st[i].x-st[k].x)*(st[i].x-st[k].x)+(st[i].y-st[k].y)*(st[i].y-st[k].y);
    	s[2]=(st[k].x-st[j].x)*(st[k].x-st[j].x)+(st[k].y-st[j].y)*(st[k].y-st[j].y);
    //	FK(s[0]);
    //	FK(s[1]);
    //	FK(s[2]);
    	sort(s,s+3,cmp);
    	if(s[0]<s[1]+s[2])return 1;
    	return 0;
    }
    
    int main() {
    	int T;
    	int n;
    	scanf("%d",&T);
    	bigfor(T) {
    		scanf("%d",&n);
    		for(int i=0; i<n; i++) {
    			scanf("%I64d%I64d",&st[i].x,&st[i].y);
    		}
    		LL ans=0;
    		for(int i=0; i<n; i++) {
    			for(int j=i+1; j<n; j++) {
    				for(int k=j+1; k<n; k++) {
    					if(check(i,j,k)) ans++;
    				}
    			}
    		}
    		printf("%I64d
    ",ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Leetcode 242.有效的字母异位词 By Python
    Leetcode 344.反转字符串 By Python
    Leetcode 217.存在重复元素 By Python
    js 动态加载select触发事件
    MUI 里js动态添加数字输入框后,增加、减少按钮无效
    【 jquery 】常用
    MySql 常用语句
    CSS 选择器 知识点
    HTML 符号实体
    log4net 配置
  • 原文地址:https://www.cnblogs.com/HDMaxfun/p/5789480.html
Copyright © 2011-2022 走看看