Codeforces 232A - Cycles (构造 + 思维)
题目链接:
232A - Cycles(点击打开)
题意:
要构成一个存在 \(k\) 个三元环的图,需要多少个点,输出顶点数 \(n\),并输出图。
题解:
题目中的任何图都可以用 \(90\)~ \(100\)个顶点构造完成。
Proof that \(100\) vertices are always enough for the given restrictions on \(n\).
- For some \(p\) after first \(p\) iterations we will have a complete graph of \(p\) vertices.
- Now we have exactly \(C(p, 3)\) triangles. Consider \(p\) such that \(C(p, 3) ≤ k\) and \(C(p, 3)\) is maximal.
- For the given restrictions \(p ≤ 85\).
- From this moment, if we add \(u\) from some vertex, we increase the total number of 3-cycles on \(C(u, 2).\)
- So we have to present a small number that is less than \(C(85, 3)\) as sum of \(C(i, 2)\).
The first number we subtruct will differ \(C(85, 1)\) on some value not greater than \(C(85, 1) = 85\), because \(C(n, k) - C(n - 1, k) = C(n - 1, k - 1)\).
- The second number we subtruct will differ the number we have on some value not greater than \(C(14, 1) = 14.\)
- and so on.
- For every \(k\) it's enough to use not more that \(90\) vertices.
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int g[123][123];
int main()
{
int k;
cin>>k;//要求的三元环个数
for(int i=0;i<90;i++)//依次增加顶点
{
int sum = 0;//三元环个数
for(int j = 0; j < i && sum <= k;j++)
{
k-=sum;
sum++;
g[i][j] = g[j][i] = 1;
}
}
cout<<90<<endl;
for(int i=0;i<90;i++)
{
for(int j=0;j<90;j++)
{
int ans = g[i][j] ? 1:0;
cout<<ans;
}
cout<<endl;
}
return 0;
}
Codeforces 232A - Cycles (构造 + 思维)的更多相关文章
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- Codeforces 755E:PolandBall and White-Red graph(构造+思维)
http://codeforces.com/contest/755/problem/E 题意:给出n个点和一个距离d,让你在这个n个点的图里面构造一个子图,使得这个子图的直径和补图的直径的较小值为d, ...
- codeforces 454 E. Little Pony and Summer Sun Celebration(构造+思维)
题目链接:http://codeforces.com/contest/454/problem/E 题意:给出n个点和m条边,要求每一个点要走指定的奇数次或者是偶数次. 构造出一种走法. 题解:可能一开 ...
- Codeforces 989 P循环节01构造 ABCD连通块构造 思维对云遮月参考系坐标轴转换
A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a ...
- Codeforces 1368E - Ski Accidents(构造+思维)
Codeforces 题面传送门 & 洛谷题面传送门 神仙构造题(不过可能我构造太烂了?) 首先考虑这个奇奇怪怪的 \(\dfrac{4}{7}\),以及这个每个点出度最多为 \(2\) 的条 ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
- Codeforces Gym101503E:XOR-omania(构造+思维)
题目链接 题意 给出m个数b,这些数是由n个数a两两异或组成的,问初始的那n个数分别是多少. 思路 存在多组解的情况...原来是个构造题. 考虑这样一种情况:b1 = a1 ^ a2,b2 = a2 ...
- codeforces 389 D. Fox and Minimal path(构造+思维)
题目链接:https://vjudge.net/contest/175446#problem/J 题解:显然要用最多n个点构成的图要使的得到的最短路条数有1e9次个,显然要有几个数相乘容易想到2的几进 ...
- Educational Codeforces Round 102 (Rated for Div. 2) B. String LCM (构造,思维)
题意:给你两个字符串\(a\)和\(b\),找出它们的\(lcm\),即构造一个新的字符串\(c\),使得\(c\)可以由\(x\)个\(a\)得到,并且可以由\(y\)个\(b\)得到,输出\(c\ ...
随机推荐
- SSH—指定登录的IP
设置ssh安全--指定的IP登陆 为了服务器更加具有安全性,我们可以设置ssh安全只允许用户从固定的IP进行登陆, 首先获取要登录服务器的电脑的IP地址 登录http://www.ip138.com/ ...
- WebCollector爬取百度搜索引擎样例
使用WebCollector来爬取百度搜索引擎依照关键字搜索的结果页面,解析规则可能会随百度搜索的改版而失效. 代码例如以下: package com.wjd.baidukey.crawler; im ...
- OpenCASCADE中散乱Edge生成Wire
OpenCASCADE中散乱Edge生成Wire eryar@163.com Abstract. In OpenCASCADE a wire can be built from any number ...
- .Net强类型视图
1.控制器 Controllers/StoreController.cs using System; using System.Collections.Generic; using System.Li ...
- 31.Intellij idea 的maven项目如何通过maven自动下载jar包
转自:https://blog.csdn.net/u012851114/article/details/81872981 maven项目自动加载jar包 所需工具如下: Intellij IDEA 1 ...
- JS --- 延迟加载的几种方式
标题:JS延迟加载,也就是等页面加载完成之后再加载 JavaScript 文件. JS延迟加载有助于提高页面加载速度. 1. defer 属性 HTML 4.01 为 <script>标 ...
- finally不管有没有错都会运行 finally 块用于清除 try 块中分配的任何资源,以及运行任何即使在发生异常时也必须执行的代码
finally 块用于清除 try 块中分配的任何资源,以及运行任何即使在发生异常时也必须执行的代码
- WPF中RichTextBox高度自适应问题解决方法
最近做一个项目需要用到RichTextBox来显示字符串,但是不允许出现滚动条,在RichTextBox宽度给定的条件下,RichTextBox的高度必须正好显示内容,而不出现下拉滚动条. 这样就要计 ...
- Ternary Tree
前一篇文章介绍了Trie树.它实现简单但空间效率低.假设要支持26个英文字母,每一个节点就要保存26个指针,因为节点数组中保存的空指针占用了太多内存.让我来看看Ternary Tree. When y ...
- 存储控制器和SDRAM 实验
S3C2440 存储控制器(memory controller)提供了訪问外部设备所需的信号,这是一种通过总线形式来訪问扩展的外设. S3C2440 的存储器控制器有下面的特性: 支持小字节序.大字 ...