• hdu 5277 YJC counts stars 暴力


    YJC counts stars

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=5277

    Description

    YJC是个老火车小司机。一个晚上,他仰望天空,星辰璀璨,他突然觉得,天空就像一个平面,而每一个星辰,就是平面中的一个点。
    他把这些点编号为1到n。这些点满足任意三点不共线。他把一些点用线段连起来了,但是任意两条线段不会在端点以外相交。如果一个点的集合中任意两个点都有一条线段直接相连,就称为dujiao点集。他想让你求出最大的dujiao点集大小以及最大的dujiao点集个数。

    Input

    多组测试。
    对于每组数据:
    第一行两个整数n,m,表示点数和线段数。
    接下来n行每行两个整数x,y,表示第i个点的坐标。
    接下来m行每行两个整数u,v,表示一条连接u和v的线段。

    Output

    对于每组数据输出两个用空格隔开的整数表示最大的dujiao点集大小以及最大的dujiao点集个数。

    Sample Input

    2 1
    1 1
    2 2
    1 2
    3 3
    1 1
    2 2
    4 5
    1 2
    2 3
    3 1

    Sample Output

    2 1
    3 1

     

    HINT

    1≤n≤1000 −109≤x,y≤109 1≤T≤5(T是数据组数)
    保证没有相同的点和相同的边,也没有u=v的情况

    题意

    题解:

    首先针对大家提出的m的数据范围的问题,其实对于平面图来说有m≤3n−6……
    首先五个点的团就是平面图判定中提到的K5,包含子图K5就不是平面图。所以答案只可能是4。
    那么怎么统计答案呢?
    暴力枚举第一个点,再枚举第二个点,在枚举第三个,第四个,要求每个点都与前面其他点联通。你会发现这就过了,为什么呢?
    枚举第一个点是O(n)的,枚举第二个点是O(n2),但是注意m=O(n),于是枚举第三个点只有O(n)次,总次数也是O(n2)的。注意到平面图三元环的个数是O(n)的,因为把一个点的相邻点按照几角排序,那么这些点的连边相当于是若干个区间,而区间不能相交,所以总共就是∑degi=O(m)(degi表示度数)的。于是枚举第四个点的次数也是O(n)的,总复杂度就是O(n2)。对于n=1000来时完全够了。

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    #define maxn 1005
    #define mod 10007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    struct node
    {
        int x,y;
    };
    node a[maxn];
    int g[maxn][maxn];
    vector<int> G[maxn];
    int one,two,three,four;
    int n,m;
    void init()
    {
        one=two=three=four=0;
        memset(a,0,sizeof(a));
        memset(g,0,sizeof(g));
        for(int i=0;i<n;i++)
            G[i].clear();
    }
    int main()
    {
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            init();
            for(int i=0;i<n;i++)
                a[i].x=read(),a[i].y=read();
            for(int i=1;i<=m;i++)
            {
                int x=read(),y=read();
                x--,y--;
                g[x][y]=g[y][x]=1;
                G[x].push_back(y);
                G[y].push_back(x);
            }
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<G[i].size();j++)
                {
                    for(int k=0;k<G[i].size();k++)
                    {
                        if(G[i][j]!=G[i][k]&&g[G[i][j]][G[i][k]])
                        {
                            three++;
                            for(int t=0;t<G[i].size();t++)
                            {
                                if(G[i][j]!=G[i][k]&&G[i][j]!=G[i][t]&&G[i][k]!=G[i][t]&&g[G[i][j]][G[i][k]]&&g[G[i][j]][G[i][t]]&&g[G[i][k]][G[i][t]])
                                {
                                    four++;
                                }
                            }
                        }
                    }
                }
            }
            if(four)
                cout<<"4 "<<four/24<<endl;
            else if(three)
                cout<<"3 "<<three/6<<endl;
            else if(m)
                cout<<"2 "<<m<<endl;
            else
                cout<<"1 "<<n<<endl;
        }
    }
  • 相关阅读:
    不使用BeanUtils,利用Java反射机制:表单数据自动封装到JavaBean
    VS2010水晶报表的添加与使用
    使用SelectClipRgn注意事项
    使用SelectClipRgn注意事项
    使用事件CreateEvent注意事项
    【转】Delphi内嵌ASM简易教程
    栈顶和栈底示意图
    【转】对ARM堆栈的理解
    UISegmentedControl的基本使用
    C语言小知识总结
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4621609.html
Copyright © 2020-2023  润新知