题目大意

我们说一个无向图是 p-interesting 当且仅当这个无向图满足如下条件:

1. 该图恰有 2 * n + p 条边

2. 该图没有自环和重边

3. 该图的任意一个包含 k 个节点的子图含有不超过 2 * k + p 条边

现在,请你找出一个 p-interesting 包含 n 个节点的无向图,输出他的 2 * n + p 条边

数据范围:5 ≤ n ≤ 24,0 ≤ p, 2 * n + p ≤ (n) * (n + 1) / 2

做法分析

好久没有做题了,刷刷水题练练手

第一感觉:乱搞,后来想了会儿,还是乱搞

构造方法:

先将所有的点连成一个环,如果边数不够,就将间隔为 1 个点的两个点对之间建立一条边,如果还不够,就将间隔为 2 个点的两点对之间建立一条边,然后是间隔为 3 的,直到边的数量到达 2 * n + p 为止

参考代码

 #include <iostream>
#include <cstring>
#include <cstdio> using namespace std; int t, n, k; void deal() {
for (int step = , cnt = ; cnt < * n + k; step ++) {
for (int i = ; i <= n && cnt < * n + k; i ++, cnt ++) {
int a = i, b = i + step;
if (b > n) b -= n;
printf("%d %d\n", a, b);
}
}
} int main() {
scanf("%d", &t);
for (int ca = ; ca <= t; ca ++) {
scanf("%d%d", &n, &k);
deal();
}
return ;
}

C. Searching for Graph

题目链接

C. Searching for Graph

Codeforces Round #236 (Div. 2) C. Searching for Graph(水构造)的更多相关文章

  1. 构造图 Codeforces Round #236 (Div. 2) C. Searching for Graph

    题目地址 /* 题意:要你构造一个有2n+p条边的图,使得,每一个含k个结点子图中,最多有2*k+p条边 水得可以啊,每个点向另外的点连通,只要不和自己连,不重边就可以,正好2*n+p就结束:) */ ...

  2. 贪心 Codeforces Round #236 (Div. 2) A. Nuts

    题目传送门 /* 贪心:每一次选取最多的线段,最大能放置nuts,直到放完为止,很贪婪! 题目读不懂多读几遍:) */ #include <cstdio> #include <alg ...

  3. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  4. Codeforces Round #236 (Div. 2)

    A. Nuts time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:st ...

  5. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  6. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

  7. Codeforces Round #236 (Div. 2)E. Strictly Positive Matrix(402E)

    E. Strictly Positive Matrix   You have matrix a of size n × n. Let's number the rows of the matrix f ...

  8. Codeforces Round #161 (Div. 2) D. Cycle in Graph(无向图中找指定长度的简单环)

    题目链接:http://codeforces.com/problemset/problem/263/D 思路:一遍dfs即可,dp[u]表示当前遍历到节点u的长度,对于节点u的邻接点v,如果v没有被访 ...

  9. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

随机推荐

  1. [游戏学习25] MFC 橡皮筋画线效果

    >_<:这是给出窗口内外不同情况的处理展示的例子. >_<:MouseCap.h #include<afxwin.h> class CMyApp :public C ...

  2. Windows下使用Redis(一)安装使用

    一.Redis 是什么 Redis 是一款依据BSD开源协议发行的高性能Key-Value存储系统(cache and store).它通常被称为数据结构服务器,因为值(value)可以是 字符串(S ...

  3. WPF oxyPlot 使用总结

    oxyPlot能够简易的创建图表并且该库也在Github上面开源直通门.以下是笔者基础使用总结.本文例子的源码下载 1.安装与引用 新建一个wpf应用程序,然后使用Nuget控制台安装OxyPlot和 ...

  4. 升级webapi依赖的Newtonsoft.json的版本

    随着微软日渐重视开源社区的贡献,微软在自己的产品中往往也会集成开源的第三方库. 比如System.Net.Http.Foramatting.dll 就依赖于Newtonsoft.json v4.5. ...

  5. atitit.spring3 mvc url配置最佳实践

    atitit.spring3 mvc url配置最佳实践 1. Url-pattern  bp 1 2. 通用星号url pattern的问题 1 3. Other code 1 4. 参考 2 1. ...

  6. python元类

    第一个实例: # coding=utf8 # 手动创建,返回一个类对象 MyShinyClass = type('MyShinyClass', () ,{}) print(MyShinyClass) ...

  7. 详解Bootstrap按钮组件(二)

    按钮下拉菜单 按钮下拉菜单仅从外观上看和下拉菜单效果基本上是一样的.它们唯一的不同是外部容器div.dropdown换成了div.btn-group <div class="btn-g ...

  8. Linux Netcat 命令——网络工具中的瑞士军刀

    原文:http://www.oschina.net/translate/linux-netcat-command netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他 ...

  9. xcode中嵌入framework(接入快用最新SDK遇到的问题)

      但xcode设置中并没有找到Embed Frameworks这个选项,使用以下方式添加 当遇到dyld: Library not loaded:xxxx  Reason: image not fo ...

  10. 在IE7下使用angularjs(转)

    在我的环境中,主要支持的浏览器为:ie7, ie8, ie9, chrome等.在试验angularjs时,发现在ie7环境下运行有问题,于是在网上搜了一下相关的内容,说HTML标签的写法要这样: & ...