链接:https://www.nowcoder.com/acm/contest/145/E
来源:牛客网

Counting 4-Cliques

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述

You love doing graph theory problems. You've recently stumbled upon a classical problem : Count the number of 4-cliques in an undirected graph.

Given an undirected simple graph G, a 4-clique of G is a set of 4 nodes such that all pairs of nodes in this set are directly connected by an edge.

This task would be too easy for you, wouldn't it? Thus, your task here is to find an undirected simple graph G with exactly k 4-cliques. Can you solve this task?

输入描述:

The first line of input contains a single integer k (1 ≤ k ≤ 106).

输出描述:

On the first line, output two space-separated integers, n, m (1 ≤ n ≤ 75, 1 ≤ m ≤ n * (n - 1) / 2). On the next m lines, output two space-separated integers denoting an edge of the graph u, v (1 ≤ u, v ≤ n), where u and v are the endpoints of the edge.Your graph must not contain any self-loops or multiple edges between the same pair of nodes. Any graph that has exactly k 4-cliques and satisfies the constraints will be accepted. It can be proven that a solution always exist under the given constraints.

示例1

输入

复制

1

输出

复制

4 6
1 2
1 3
1 4
2 3
2 4
4 3

说明

In the sample, the whole graph is a 4-clique.

题意:输出k个k派系。什么是k派系?k派系就是总共四个点任何两点都可相互到达(即四个点的完全图),然后输出只有k个k派系的图。

分析:如果C(n,4)==k,那么就是n个点的完全图了。如果不相等,找到C(t,4)<=k的最大的t,然后再补上少的。

怎么补少的就是在t个点的完全图上在加一个点,向完全图连边。

1.构造一个大小为t的完全图,和a, b, c, d, e五个点。
2.a, b, c, d, e五个点之间没有边,他们只会向t个点连边。

3.如果连了x个,构成C(x, 3)个大小为4个团。
4.找到最大的t,枚举a,b,c,d,计算e。

为什么是五个点??

C(70,4)+4*C(70,3)>1e6、C(70,4)+5*C(70,3)>1e6。为什么额外五个点而不是额外四个点??

因为如果比完全图额外多17个派系,就必须用五个点构造出来

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;ll C4(ll n) { // C(n, 4)ll ans = n * (n - 1) * (n - 2) * (n - 3) / (1 * 2 * 3 * 4);return ans;
}ll C3(ll n) { // C(n, 3)ll ans = n * (n - 1) * (n - 2) / (1 * 2 * 3);return ans;
}ll mp[200000 + 5];
int k;int main() {memset(mp, -1, sizeof(mp));for (ll i = 1; i <= 100; i++) {mp[C3(i)] = i;}scanf("%d", &k);ll C = 70;ll t = 4;while ((t + 1) <= C && C4(t + 1) <= k) {t++;}C = min(C, t);ll a, b, c, d, e = -1;for (a = 2; a <= C; a++) {for (b = 2; b <= C; b++) {for (c = 2; c <= C; c++) {for (d = 2; d <= C; d++) {ll cnt = C3(a) + C3(b) + C3(c) + C3(d);if (cnt <= k - C4(t)&& mp[k - C4(t) - cnt] >= 0&& mp[k - C4(t) - cnt] <= C) {e = mp[k - C4(t) - cnt];break;}}if (e != -1)    break;}if (e != -1)    break;}if (e != -1)    break;}printf("%lld %lld\n", t + 5, t * (t - 1) / 2 + a + b + c + d + e);for (int i = 1; i <= t; i++) {for (int j = i + 1; j <= t; j++) {printf("%d %d\n", i, j);}}for (int j = 1; j <= a; j++)    printf("%lld %d\n", t + 1, j);for (int j = 1; j <= b; j++)    printf("%lld %d\n", t + 2, j);for (int j = 1; j <= c; j++)    printf("%lld %d\n", t + 3, j);for (int j = 1; j <= d; j++)    printf("%lld %d\n", t + 4, j);for (int j = 1; j <= e; j++)    printf("%lld %d\n", t + 5, j);
}

Counting 4-Cliques相关推荐

  1. E - Counting Cliques HDU - 5952

    E - Counting Cliques HDU - 5952 题意: 给你n个点,m个边,还有一个s,问这个图中有多少个等于s的点集可以组成一个完全图 题解: 这题..直接暴力搜索就行 分析复杂度的 ...

  2. HDU 5952 Counting Cliques(2016ACM/ICPC亚洲区沈阳站-重现赛)

    题目分析 这道题看样子没有什么办法,主要就是有策略的暴力,因为每个点连接的点不超过20个,那么就可以直接进行暴力,但是这样会有很多重复,因此需要剪枝,具体情况就是每次搜过一个点之后就把这个点连接的所有 ...

  3. DFS:深入优先搜索 POJ-2386 Lake Counting

    深度优先搜索是从最开始的状态出发,遍历所有可以到达的状态. 因此可以对所有的状态进行操作,或列举出所有的状态. Lake Counting POJ - 2386 Due to recent rains ...

  4. Boring counting HDU - 3518 (后缀数组)

    Boring counting \[ Time Limit: 1000 ms \quad Memory Limit: 32768 kB \] 题意 给出一个字符串,求出其中出现两次及以上的子串个数,要 ...

  5. pat1004. Counting Leaves (30)

    1004. Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A fam ...

  6. CF990G GCD Counting(树上莫比乌斯反演,分层图,并查集)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Problem 给定一棵点带权无根树,对于每个 k∈[1,2×105]k\in[1,2\times10 ...

  7. 2019 ACM - ICPC 上海网络赛 E. Counting Sequences II (指数型生成函数)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  8. 人群密度估计--Structured Inhomogeneous Density Map Learning for Crowd Counting

    Structured Inhomogeneous Density Map Learning for Crowd Counting https://arxiv.org/abs/1801.06642 针对 ...

  9. 人群密度估计--Leveraging Unlabeled Data for Crowd Counting by Learning to Rank

    Leveraging Unlabeled Data for Crowd Counting by Learning to Rank CVPR2018 https://github.com/xialeil ...

  10. 人群密度估计--Crowd Counting Via Scale-adaptive Convolutional Nerual Network

    Crowd Counting Via Scale-adaptive Convolutional Nerual Network https://arxiv.org/abs/1711.04433v2 Co ...

最新文章

  1. linux下软件多语言开发,Qt,多语言软件,开发流程【总结】
  2. SQL 2005 中的数据约束
  3. STM32 基础系列教程 11 – ADC 轮询
  4. C#复制和深度复制的实现方法
  5. 团队编程项目作业1-成员简介及分工
  6. 计算机二级access上机题,计算机二级ACCESS上机题库
  7. 【转】 CSS3实现10种Loading效果
  8. Bailian2793 孙子问题【扩展欧几里德算法+中国剩余定理】
  9. python 迭代器 生成器 区别_Python的生成器和迭代器之间的区别
  10. 虚拟机vBox xp系统无法联网
  11. Holy Grail【spfa签到题】
  12. 计算机学报在线阅读,计算机学报CHIN.pdf
  13. 关于erf()与erfc()
  14. C语言实现飞翔的小鸟小游戏
  15. MySQL高可用和灾备调研
  16. 京东七夕报名要注意什么?四川万顿思
  17. 台式计算机的选购标准,如何选购台式电脑机箱?小白装机选购电脑机箱知识指南(2)...
  18. 三洋服务器显示F6,三洋空调故障代码有哪些?
  19. 【生物信息】ESTIMATE 分析免疫评分和肿瘤纯度
  20. Spring源码窥探之:ImportBeanDefinitionRegistrar

热门文章

  1. python实现规则引擎_python – 如何在不使用eval()或exec()的情况下创建规则引擎?...
  2. python必背100源代码-100行Python代码实现自动抢火车票(附源码)
  3. 零基础学python实战-Python3零基础入门到爬虫实战
  4. 零基础学python用哪本书好-零基础自学python3 好用的入门书籍推荐
  5. 为什么都建议学java而不是python-现在学Python还是Java好呢?
  6. 免费python课程排行榜-用python爬取2017年中国最好大学排名
  7. VB589语音识别芯片开发
  8. react周期函数介绍
  9. 【排序】剑指offer:数组中重复的数字
  10. sqlserver 没有备份误删数据_数据库服务器如何备份详细教程!