热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

牛客网暑期ACM多校训练营(第七场)E:Counting4Cliques(思维)

链接:https:www.nowcoder.comacmcontest145E时间限制:CC1秒,其他语言2秒空间限制:C

链接:https://www.nowcoder.com/acm/contest/145/E

时间限制: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(1k106)k(1≤k≤106).
输出描述:
On the first line, output two space-separated integers, n,m(1n75,1mn(n1)/2).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(1u,vn)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.

题解:构造一个大小为tt的完全图,和a,b,c,d,e" role="presentation" >a,b,c,d,e五个点。
a,b,c,d,ea,b,c,d,e五个点之间没有边,他们只会向tt个点连边。
• 如果连了x" role="presentation" >x个,构成C3xCx3个大小为4的团。
• 找到最大的tt,枚举a,b,c,d," role="presentation" >abcd计算ee
• 也可以直接背包,并且记录方案。
• 时间复杂度704" role="presentation" >704或者是背包复杂度

#include
using namespace std;
const int MAX=1e6+10;
const int MOD=1e9+7;
typedef long long ll;
ll c[100][5];
ll v[MAX];
void init()
{c[3][3]&#61;c[4][4]&#61;1;for(int i&#61;5;i<&#61;80;i&#43;&#43;)c[i][4]&#61;c[i-1][4]*i/(i-4);for(int i&#61;4;i<&#61;80;i&#43;&#43;)c[i][3]&#61;c[i-1][3]*i/(i-3);for(int i&#61;3;i<&#61;80;i&#43;&#43;)v[c[i][3]]&#61;i;
}
int main()
{init();int cnt;cin>>cnt;int n;for(int i&#61;1;i<&#61;70&&c[i][4]<&#61;cnt;i&#43;&#43;)n&#61;i;cnt-&#61;c[n][4];for(int i&#61;0;i<&#61;n;i&#43;&#43;)for(int j&#61;0;j<&#61;i;j&#43;&#43;)for(int k&#61;0;k<&#61;j;k&#43;&#43;)for(int h&#61;0;h<&#61;k;h&#43;&#43;){int res&#61;cnt-(c[i][3]&#43;c[j][3]&#43;c[k][3]&#43;c[h][3]);if(res<0)break;if(v[res]>n||(res&&v[res]&#61;&#61;0))continue;printf("%d %d\n",n&#43;(i>0)&#43;(j>0)&#43;(k>0)&#43;(h>0)&#43;(v[res]>0),n*(n-1)/2&#43;i&#43;j&#43;k&#43;h&#43;v[res]);for(int x&#61;1;x<&#61;n;x&#43;&#43;)for(int y&#61;x&#43;1;y<&#61;n;y&#43;&#43;)printf("%d %d\n",x,y);if(i)n&#43;&#43;;for(int x&#61;1;x<&#61;i;x&#43;&#43;)printf("%d %d\n",n,x);if(j)n&#43;&#43;;for(int x&#61;1;x<&#61;j;x&#43;&#43;)printf("%d %d\n",n,x);if(k)n&#43;&#43;;for(int x&#61;1;x<&#61;k;x&#43;&#43;)printf("%d %d\n",n,x);if(h)n&#43;&#43;;for(int x&#61;1;x<&#61;h;x&#43;&#43;)printf("%d %d\n",n,x);if(v[res])n&#43;&#43;;for(int x&#61;1;x<&#61;v[res];x&#43;&#43;)printf("%d %d\n",n,x);return 0;}return 0;
}

推荐阅读
  • 1print过程procprint<data数据集名><选项>;*label指定打印输出标签noobs制定不显示观测序号*by变量名1< ... [详细]
  • des算法php,Des算法属于加密技术中的
    本文目录一览:1、des是什么算法2、80分求 ... [详细]
  • 基础浮点数是用机器上浮点数的本机双精度(64bit)表示的。提供大约17位的精度和范围从-308到308的指数。和C语言里面的double类型相同。Python不支持32bit的 ... [详细]
  • 密码库LibTomCrypt学习记录——(2.29)分组密码算法的工作模式——KeyWrap密钥封装模式
    密钥封装(KeyWrap)密钥封装是为了对密钥进行保护,比如密钥存储在不太安全的存储设备中,或者密钥需要在网络中传输。早在2001年, ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • 预备知识可参考我整理的博客Windows编程之线程:https:www.cnblogs.comZhuSenlinp16662075.htmlWindows编程之线程同步:https ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了重温Linux内核:互斥和同步相关的知识,希望对你有一定的参考价值。文章目录 ... [详细]
  • 显卡750ti价格(750ti显卡发行价格)
    |责编:林光楠在当前这个B2BB2C逐步取代传统卖场占据主导地位的时代,通过电商、淘宝平台直接购买电脑相信已经成了不少对DIY认识不太深入的主流用户首选的配机方案。相比线下购买,网 ... [详细]
  • python数据的精度(Python小数精度)
    本文目录一览:1、python数据类型有哪些2 ... [详细]
author-avatar
人帅刀快爱美女_915
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有