A 牛牛的三角形
题目地址:
基本思路:
简单题,然而我WA了两次,可能这就是憨批吧QAQ......,直接暴力枚举三条边就好了,还是不要搞那些花里花俏的。
三角形无脑判定满足下面三个就好了:
- a+b>c
- a+c>b
- b+c>a
参考代码:
#pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; #define IO std::ios::sync_with_stdio(false) #define int long long #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) #define mset(s, _) memset(s, _, sizeof(s)) #define pb push_back #define pii pair <int, int> #define mp(a, b) make_pair(a, b) #define INF 0x3f3f3f3f inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); } return neg * x; } inline void print(int x) { if (x < 0) { putchar('-'); x = -x; } if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } const int maxn = 110; int n,arr[maxn]; signed main() { IO; cin >> n; rep(i,1,n) cin >> arr[i]; bool v = false; rep(i,1,n){ rep(j,i+1,n){ rep(k,j+1,n){ int a = arr[i],b = arr[j],c = arr[k]; if(a + b > c && a + c > b && b + c > a){ cout << a << ' ' << b << ' ' << c << '\n'; return 0; } } } } cout << "No solution" << '\n'; return 0; }