{ "question_id": 1062008, "question_title": "请问一共可以有多少种取木棍的方案", "question_content": "目前有一个长度为 n 的木棍,当做直角三角形的斜边。A,B,C要从许多整数长度的木棍中选出三根,分别长为 a, b, c。 现在,蒜头君和花椰妹的木棍组成一条直角边长度为 a + b,白菜君组成另外一条直角边 c,并且要求 a + b ≤ c。请问一共可以有多少种取木棍的方案。 提示:a = 3, b = 4 与 a = 4, b = 3 算作同一种方案。", "difficulty": "中等", "answer_id": 1259875, "answer_content": "\n```\n#include \n\nint main()\n{\n\tint n;\n\tint cnt = 0;\n\tscanf(\"%d\", &n);\n\tfor (int a = 1; a < n; a++)\n\t\tfor (int b = a; b < n - a; b++)\n\t\t\tfor (int c = 1; c < n; c++)\n\t\t\t{\n\t\t\t\tif ((a+b)*(a+b)+c*c==n*n)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"a=%d b=%d c=%d\\n\", a, b, c);\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\tprintf(\"一共有%d种方案\", cnt);\n\treturn 0;\n}\n```\n5\na=1 b=2 c=4\na=1 b=3 c=3\na=2 b=2 c=3\n一共有3种方案Press any key to continue . . .\n\n\n10\na=1 b=5 c=8\na=1 b=7 c=6\na=2 b=4 c=8\na=2 b=6 c=6\na=3 b=3 c=8\na=3 b=5 c=6\na=4 b=4 c=6\n一共有7种方案Press any key to continue . . .\n\n", "tag_name": "c++", "cpp": "#include \nint main()\n{\n\tint n;\n\tint cnt = 0;\n\tscanf(\"%d\", &n);\n\tfor (int a = 1; a < n; a++)\n\t\tfor (int b = a; b < n - a; b++)\n\t\t\tfor (int c = 1; c < n; c++)\n\t\t\t{\n\t\t\t\tif ((a+b)*(a+b)+c*c==n*n)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"a=%d b=%d c=%d\\n\", a, b, c);\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\tprintf(\"一共有%d种方案\", cnt);\n\treturn 0;\n}", "topic_link": "https://bbs.csdn.net/topics/600469852", "status": 1, "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/68.ipynb?type=file" }, "notebook_enable": 1 }