AtCoder Beginner Contest 145

传送门

A - Circle

签到。

B - Echo

签到到。

C - Average Length

要卡下精度,可用二分或者long double来搞。


Code

/*
 * Author:  heyuhhh
 * Created Time:  2019/11/16 20:04:44
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 10;
const double eps = 1e-6;
int n;
struct Point{
    int x, y;   
}p[N];
int a[N];
double dis(Point A, Point B) {
    double tmp = 1.0 * (A.x - B.x) * (A.x - B.x) + 1.0 * (A.y - B.y) * (A.y - B.y);   
    double l = 0, r = tmp, mid;
    for(int i = 1; i <= 500; i++) {
        mid = (l + r) / 2;
        if(mid * mid < tmp) l = mid;
        else r = mid;   
    }
    return r;
}
void run(){
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y;
    for(int i = 1; i <= n; i++) a[i] = i;
    double ans = 0;
    int tot = 0;
    do {
        ++tot;
        for(int i = 2; i <= n; i++) {
            ans += dis(p[a[i]], p[a[i - 1]]);
        }
    } while(next_permutation(a + 1, a + n + 1));
    ans = ans / tot;
    cout << ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}
上一篇:【LeetCode】145. Binary Tree Postorder Traversal


下一篇:[LeetCode 解题报告]145. Binary Tree Postorder Traversal