题目链接:

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 (构造 + 思维)的更多相关文章

  1. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  2. Codeforces 755E:PolandBall and White-Red graph(构造+思维)

    http://codeforces.com/contest/755/problem/E 题意:给出n个点和一个距离d,让你在这个n个点的图里面构造一个子图,使得这个子图的直径和补图的直径的较小值为d, ...

  3. codeforces 454 E. Little Pony and Summer Sun Celebration(构造+思维)

    题目链接:http://codeforces.com/contest/454/problem/E 题意:给出n个点和m条边,要求每一个点要走指定的奇数次或者是偶数次. 构造出一种走法. 题解:可能一开 ...

  4. Codeforces 989 P循环节01构造 ABCD连通块构造 思维对云遮月参考系坐标轴转换

    A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a ...

  5. Codeforces 1368E - Ski Accidents(构造+思维)

    Codeforces 题面传送门 & 洛谷题面传送门 神仙构造题(不过可能我构造太烂了?) 首先考虑这个奇奇怪怪的 \(\dfrac{4}{7}\),以及这个每个点出度最多为 \(2\) 的条 ...

  6. 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 ...

  7. Codeforces Gym101503E:XOR-omania(构造+思维)

    题目链接 题意 给出m个数b,这些数是由n个数a两两异或组成的,问初始的那n个数分别是多少. 思路 存在多组解的情况...原来是个构造题. 考虑这样一种情况:b1 = a1 ^ a2,b2 = a2 ...

  8. codeforces 389 D. Fox and Minimal path(构造+思维)

    题目链接:https://vjudge.net/contest/175446#problem/J 题解:显然要用最多n个点构成的图要使的得到的最短路条数有1e9次个,显然要有几个数相乘容易想到2的几进 ...

  9. Educational Codeforces Round 102 (Rated for Div. 2) B. String LCM (构造,思维)

    题意:给你两个字符串\(a\)和\(b\),找出它们的\(lcm\),即构造一个新的字符串\(c\),使得\(c\)可以由\(x\)个\(a\)得到,并且可以由\(y\)个\(b\)得到,输出\(c\ ...

随机推荐

  1. php自定义加密和解密

    <?php function _authcode($string, $operation = 'DECODE', $expiry = 0) { $key = 'c5s1t6o';    $cke ...

  2. this对象的理解

    (回答一:) (1).js的this指向是不确定的,也就是说是可以动态改变的.call/apply 就是用于改变this指向的函数,这样设计可以让代码更加灵活,复用性更高 (2).this 一般情况下 ...

  3. CodeForcesGym 100502G Outing

    Outing Time Limit: 1000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGym. Origi ...

  4. Activiti工作流(4):编写一个HelloWorld

    版权声明:本文为博主原创文章,未经博主允许不得转载. 1.使用eclipse的activiti插件画流程图 在resource文件夹下新建一个工作流diagram 右键——new——other...— ...

  5. python调用Java代码,完毕JBPM工作流application

    1.缘由 有一庞大Python django webproject,要引入工作流引擎,像OA一样.方便的流程控制与管理.Python或django关于工作流的开源插件,稀少,并且弱爆了,终于选用jav ...

  6. Raid阵列之简单介绍

    1.raid分类 软raid:用软件模拟raid芯片 硬raid:集成的后来添加的 2.raid基本简介 (1)raid是由廉价磁盘冗余阵列发展成为独立磁盘冗余阵列 (2)linux是借助MD(Mui ...

  7. 用AOP改善javascript代码

    Aop又叫面向切面编程,用过spring的同学肯定对它非常熟悉,而在js中,AOP是一个被严重忽视的技术点,这篇就通过下面这几个小例子,来说说AOP在js中的妙用. 1, 防止window.onloa ...

  8. Day5费用流

    算法 zkw费用流:多路增广,增光D[y]=D[i]+c的边 无源汇上下界最小费用可行流 每次强行增加下界的流量 类似网络流,拆边 原边的费用为c,拆出来的边费用为0 负边和负圈 直接应用 SDOI2 ...

  9. js中Object.defineProperties 定义一个在原对象可读可写的方法

    function A(){ this.name = 'hellow word'; } Object.defineProperties( A.prototype,{ doSomething2 : { v ...

  10. Kinect 开发 —— 手势识别(上)

    像点击(clicks)是GUI平台的核心,轻点(taps)是触摸平台的核心那样,手势(gestures)是Kinect应用程序的核心 关于手势的定义的中心在于手势能够用来交流,手势的意义在于讲述而不是 ...