zoukankan      html  css  js  c++  java
  • bzoj 2530 [Poi2011]Party 构造

    2530: [Poi2011]Party

    Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special Judge
    Submit: 364  Solved: 213
    [Submit][Status][Discuss]

    Description

    给定一张N(保证N是3的倍数)个节点M条边的图,并且保证该图存在一个大小至少为2N/3的团。
    请输出该图的任意一个大小为N/3的团。 一个团的定义为节点的一个子集,该子集中的点两两有直接连边。 输入: 第一行是两个整数N,M。 接下来有M行,每行两个整数A,B,表示A和B有连边。保证无重边。 
    输出: N/3个整数,表示你找到的团。 数据范围: 
     

    3<=N<=3000,[3/2 n(2/3 n -1)]/2<=M<=[n(n-1)/2]

    Input

    In the first line of the standard input two integers, n and M(3<=N<=3000,[3/2 n(2/3 n -1)]/2<=M<=[n(n-1)/2]), are given, separated by a single space. These denote the number of Byteasar's friends and the number of pairs of his friends who know each other, respectively. Byteasar's friends are numbered from 1 to . Each of the following lines holds two integers separated by a single space. The numbers in line no.i+1(for i=1,2,...,m) are Ai and Bi(1<=Ai<Bi<=N), separated by a single space, which denote that the persons Ai and Bi now each other. Every pair of numbers appears at most once on the input.

    Output

    In the first and only line of the standard output your program should print N/3numbers, separated by single spaces, in increasing order. These number should specify the numbers of Byteasar's friends whom he should invite to the party. As there are multiple solutions, pick one arbitrarily.

    Sample Input

    6 10
    2 5
    1 4
    1 5
    2 4
    1 3
    4 5
    4 6
    3 5
    3 4
    3 6

    Sample Output

    2 4
     
    如果两个点没连边,则不可能属于团,所以直接去除,n^2的复杂度即可。
     
     1 #include<cstring>
     2 #include<cmath>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<iostream>
     6 
     7 #define N 3007
     8 
     9 #define Wb putchar(' ')
    10 #define We putchar('
    ')
    11 #define rg register int
    12 using namespace std;
    13 inline int read()
    14 {
    15     int x=0,f=1;char ch=getchar();
    16     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    17     while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    18     return x*f;
    19 }
    20 inline void write(int x)
    21 {
    22     if(x<0) putchar('-'),x=-x;
    23     if (x==0) putchar(48);
    24     int num=0;char c[15];
    25     while(x) c[++num]=(x%10)+48,x/=10;
    26     while(num) putchar(c[num--]);
    27 }
    28 
    29 int n,m,cnt;
    30 int a[N][N],vis[N];
    31 
    32 int main()
    33 {
    34     n=read(),m=read();
    35     for (rg i=1;i<=m;i++)
    36     {
    37         int x=read(),y=read();
    38         a[x][y]=a[y][x]=true;
    39     }
    40     for (int i=1;i<=n;i++)
    41         for (int j=i+1;j<=n&&!vis[i];j++)
    42             if (!vis[j]&&!a[i][j])
    43                 vis[i]=vis[j]=true;
    44     for (int i=1;i<=n&&cnt<n/3;i++)
    45         if (!vis[i]) write(i),Wb;
    46 }
  • 相关阅读:
    iOS崩溃治理--基础设施篇
    iOS崩溃治理--开篇
    AFNetworking 源码解读
    NSURLSession使用, 后台下载
    iOS10 越狱, openSSH
    iOS 私有API调用
    IOS 中openGL使用(使用基准图快速制作滤镜)
    IOS 中openGL使用教程4(openGL ES 入门篇 | 离屏渲染)
    IOS 中openGL使用教程3(openGL ES 入门篇 | 纹理贴图(texture)使用)
    SSM整合配置文件的主要内容
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/8983600.html
Copyright © 2011-2022 走看看