|
发表于 2020-2-26 17:29:11
|
显示全部楼层
本帖最后由 guoquanli 于 2020-2-26 17:33 编辑
- /*功能函数,实现直角三角形个数的计算*/
- int calNumOfTag(int pointA){
- int tagNum = 0;
- int count = 0;
- for(int x1 = 0; x1 <= pointA; x1++){
- for(int y1 = 0; y1<=pointA; y1++){
- for(int x2 = 0; x2 <= pointA; x2++){
- for(int y2 = 0; y2<= pointA ; y2++){
- if((x1 == x2 && y1 == y2)|| (x1 == 0 && y1 == 0) || (x2 ==0 && y2 == 0)){
- continue;
- }
- //count++;
- //printf("符合条件的点的集合___%d____:A(%d,%d),B(%d,%d)\n",count,x1,y1,x2,y2);
- //printf("*******\n");
- int edge_1 = x1*x1 + y1*y1;
- //printf("edge_1 = x1*x1 + y1*y1[%d]\n",edge_1);
- int edge_2 = x2*x2 + y2*y2;
- //printf("edge_2 = x2*x2 + y2*y2[%d]\n",edge_2);
- int edge_3 = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 -y1);
- //printf("edge_3 = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 -y1)[%d]\n",edge_3);
- if(edge_1 + edge_2 == edge_3 || edge_1 + edge_3 == edge_2 || edge_3 + edge_2 == edge_1 ){
- tagNum++;
- //printf("能组成直角三角形的点是:B(%d,%d),C(%d,%d)\n",x1,y1,x2,y2);
- }
- }
- }
- }
- }
- return tagNum/2 ;
复制代码
答案:14234 |
|