zoukankan      html  css  js  c++  java
  • Codeforces 333E Summer Earnings(bitset)

    题目链接 Summer Earnings

    类似MST_Kruskal的做法,连边后sort。

    然后对于每条边,依次处理下来,当发现存在三角形时即停止。(具体细节见代码)

    答案即为发现三角形时当前所在边长度的一半。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    struct node{
        int x, y, z;
        friend bool operator < (const node &a, const node &b){
            return a.z > b.z;
        }
    } p[4600010];
    
    int a[3010], b[3010];
    int n, cnt = 0;
    
    bitset <3010> c[3010], tmp;
    
    int main(){
    
        scanf("%d", &n);
    
        for (int i = 1; i <= n; ++i) scanf("%d%d", a + i, b + i);
        for (int i = 1; i <= n - 1; ++i) for (int j = i + 1; j <= n; ++j)
            p[++cnt].x = i, p[cnt].y = j, 
            p[cnt].z = (a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]);
    
        sort(p + 1, p + cnt + 1);
    
        for (int i = 1; i <= cnt; ++i){
            int x = p[i].x, y = p[i].y;
            tmp = c[x] & c[y];
            if (tmp.any()) return 0 * printf("%.10f
    ", sqrt(1.00 * p[i].z) / 2);
            c[x].set(y), c[y].set(x);
        }    
    
    
        return 0;
    
    }
    
  • 相关阅读:
    iSCSI又称为IPSAN
    文档类型定义DTD
    HDU 2971 Tower
    HDU 1588 Gauss Fibonacci
    URAL 1005 Stone Pile
    URAL 1003 Parity
    URAL 1002 Phone Numbers
    URAL 1007 Code Words
    HDU 3306 Another kind of Fibonacci
    FZU 1683 纪念SlingShot
  • 原文地址:https://www.cnblogs.com/cxhscst2/p/6720301.html
Copyright © 2011-2022 走看看