3 条题解

  • 2
    @ 2023-7-30 21:13:40
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int x, y, z, n, sum = 0;
        cin >> n;
        for (x = 1; x <= n - 2; x ++)
        {
            for (y = 1; y <= n - x - 1; y ++)
            {
                z = n - x - y;
                if (x + y > z && x + z > y && y + z >x)
                {
                    if (x == y && x == z)
                    {
                        continue;
                    }
                    else if (x == y || x == z || y == z)
                    {
                        sum += 2;
                    }
                    else
                    {
                        sum++;
                    }
                }
            }
        }
        sum = sum / 6;
        cout << sum;
        return 0;
    }
    
    • 2
      @ 2022-12-10 15:55:42
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          int a, b, c, n, x = 0;
          cin >> n;
          for (a = 1; a <= n - 2; a += 1)
          {
              for (b = 1; b <= n - a - 1; b += 1)
              {
                  c = n - a - b;
                  if (a + b > c && a + c > b && b + c > a)
                  {
                      if (a == b && a == c)
                      {
                          continue;//等边
                      }
                      else if (a == b || a == c || b == c)
                      {
                          x += 2;//等腰增加记数2
                      }
                      else
                      {
                          x += 1;//增加记数1
                      }
                  }
              }
          }
          x = x / 6;//考虑组合缩减数量
          cout << x;
          return 0;
      }//代码已AC
      
      • 1
        @ 2023-7-7 21:27:41

        已AC``` #include <iostream> using namespace std; int main() { int L; cin >> L; int num = 0; int num1 = 0;//有两条边相等 int num2 = 0;//三条边都不相等 for (int i = 1; 2i < L; i++) { for (int j = 1; 2j < L; j++) { if (i+j<L&&2i+2j>L&&L-i-j>0)//这是成为三角形的条件,经过化简之后得到可以自己算算 { if (!(3i==L&&3j==L&&3*(L-i-j)==L))//括号内是等边三角形的情况,前面加上!为非等边三角形 //一定要注意这里不能写成i!=j&&j!=L-i-j&&i!=L-i-j,因为这样等腰三角形的情况会被吞掉 { if (i != j && j != (L - i - j) && i != (L - i - j)) { num2++; } else { num1++; } } } } } num = num1 / 3 + num2 / 6;//两条边相等的排列方式有3种,三条边互异的排列方式有6种 cout << num; return 0; }

        
        
        
        
        • 1

        信息

        ID
        80
        时间
        1000ms
        内存
        16MiB
        难度
        3
        标签
        递交数
        115
        已通过
        66
        上传者