top1编程
← 返回题目
题解

三角形的个数

1 条题解

  • 0
    @ 2026-7-29 0:19:57
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	//最短边:1~l/3
    	//中间:1~l/2
    	//最长=l-最短-中间
    	int l,s=0;
    	cin>>l;
    	for(int i=1;i<=l/3;i++){
    		for(int j=i;j<=l/2;j++){
    			int k=l-i-j;
    			if(i+j>k&&i+k>j&&j+k>i){
    				if(k==j&&j!=i||k>j){//不是等边
    					s++;
    				}
    			}
    		}
    	}
    	cout<<s;
    	return 0;
    }
    
    • 1