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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';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=;
memset(a,,sizeof(a));
memset(g,,sizeof(g));
for(int i=;i<n;i++)
G[i].clear();
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
init();
for(int i=;i<n;i++)
a[i].x=read(),a[i].y=read();
for(int i=;i<=m;i++)
{
int x=read(),y=read();
x--,y--;
g[x][y]=g[y][x]=;
G[x].push_back(y);
G[y].push_back(x);
}
for(int i=;i<n;i++)
{
for(int j=;j<G[i].size();j++)
{
for(int k=;k<G[i].size();k++)
{
if(G[i][j]!=G[i][k]&&g[G[i][j]][G[i][k]])
{
three++;
for(int t=;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/<<endl;
else if(three)
cout<<"3 "<<three/<<endl;
else if(m)
cout<<"2 "<<m<<endl;
else
cout<<"1 "<<n<<endl;
}
}

hdu 5277 YJC counts stars 暴力的更多相关文章

  1. hdu 5277 YJC counts stars

    hdu 5277 YJC counts stars 题意: 给出一个平面图,n个点,m条边,直线边与直线边之间不相交,求最大团的数目. 限制: 1 <= n <= 1000 思路: 因为平 ...

  2. HDU 2920 分块底数优化 暴力

    其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...

  3. hdu 5276 YJC tricks time 数学

    YJC tricks time Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  4. HDU 5762 Teacher Bo (暴力)

    Teacher Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...

  5. hdu 4712 Hamming Distance(随机函数暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  6. hdu 4876 ZCC loves cards(暴力)

    题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...

  7. HDU - 5276 YJC tricks time

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5276   Sample Input 99000 0   Sample Output 00:01:30 ...

  8. HDU 5442 Favorite Donut(暴力 or 后缀数组 or 最大表示法)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 题意:给出一串字符串,它是循环的,现在要选定一个起点,使得该字符串字典序最大(顺时针和逆时针均可),如果有 ...

  9. HDU 5273 Dylans loves sequence 暴力递推

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...

随机推荐

  1. MAC OSX 驱动操作

    mac ox系统的驱动安装常规操作:下载到 *.kext 的驱动以后,都可以直接把它拖到 /System/Library/Extensions/ 下替换掉原来的文件.替换了以后,还需要修复权限才能够正 ...

  2. db file sequential read (数据文件顺序读取)

    转载:http://www.dbtan.com/2010/04/db-file-sequential-read.html db file sequential read (数据文件顺序读取): db ...

  3. 《Windows核心编程》第5版 学习进度备忘

    学习资源:<Windows核心编程>第5版 知识基础支持: 本书与<Windows程序设计>第5版珍藏版结合很好,二者重叠内容不多,二者互补性强,而且相关方面的优秀书籍 跳过的 ...

  4. python中的多线程【转】

    转载自: http://c4fun.cn/blog/2014/05/06/python-threading/ python中关于多线程的操作可以使用thread和threading模块来实现,其中th ...

  5. 写在阿里去IOE一周年

    [文/ 任英杰] 去年5月17日,阿里巴巴支付宝最后一台IBM小型机在下线,标志着阿里完成去IOE.随后一场去IOE运动不断发酵,甚至传闻IBM中国去年损失了20%的合同额. 去了IOE,奔向何方?阿 ...

  6. 初识 istringstream、ostringstream、stringstream 运用

    今天编程练习时遇到了istringstream的用法,感觉很实用.后面附题目! C++的输入输出分为三种: (1)基于控制台的I/O (2)基于文件的I/O (3)基于字符串的I/O 1.头文件  # ...

  7. Android Audio遇到播放无声时的分析

    在Android Audio开发过程中,有遇到播放ringtone时无声,但播放Music可以听到声音,关于无声问题的分析,在此做个笔记,方便以后回顾. 分析方向: 1:在音量控制面板中确认该音频流对 ...

  8. How to Keep Alive SSH Sessions

    How to Keep Alive SSH Sessions Many NAT firewalls time out idle sessions after a certain period of t ...

  9. C#获取ftp文件最后修改时间

    public static DateTime GetFileModifyDateTime(string ftpServerIP,string ftpFolder,string ftpUserID,st ...

  10. mysql 中时间和日期函数应用

    一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +-------------------- ...