Codeforces Round #236 (Div. 2) C. Searching for Graph(水构造)
题目大意
我们说一个无向图是 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
题目链接
Codeforces Round #236 (Div. 2) C. Searching for Graph(水构造)的更多相关文章
- 构造图 Codeforces Round #236 (Div. 2) C. Searching for Graph
题目地址 /* 题意:要你构造一个有2n+p条边的图,使得,每一个含k个结点子图中,最多有2*k+p条边 水得可以啊,每个点向另外的点连通,只要不和自己连,不重边就可以,正好2*n+p就结束:) */ ...
- 贪心 Codeforces Round #236 (Div. 2) A. Nuts
题目传送门 /* 贪心:每一次选取最多的线段,最大能放置nuts,直到放完为止,很贪婪! 题目读不懂多读几遍:) */ #include <cstdio> #include <alg ...
- 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 ...
- Codeforces Round #236 (Div. 2)
A. Nuts time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:st ...
- 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 ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- 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 ...
- Codeforces Round #161 (Div. 2) D. Cycle in Graph(无向图中找指定长度的简单环)
题目链接:http://codeforces.com/problemset/problem/263/D 思路:一遍dfs即可,dp[u]表示当前遍历到节点u的长度,对于节点u的邻接点v,如果v没有被访 ...
- 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 ...
随机推荐
- JAXB命名空间及命名空间前缀处理
本篇介绍下JAXB进阶使用,命名空间处理 使用package-info.java添加默认命名空间在需要添加命名空间的包下面添加package-info.java文件,然后添加@XmlSchema注解, ...
- 使用grunt打包ueditor源代码
支持版本支持 UEditor 1.3.0+ 的版本 使用方法1.线上下载ueditor下载地址:ueditor,要下载"完整版 + 源码" 2.安装nodejs下载nodejs并安 ...
- canvas/CSS实现仪表盘效果
手机上看比较虚 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...
- 浅谈压缩感知(二十九):压缩感知算法之迭代硬阈值(IHT)
主要内容: 1.IHT的算法流程 2.IHT的MATLAB实现 3.二维信号的实验与结果 4.加速的IHT算法实验与结果 一.IHT的算法流程 文献:T. Blumensath and M. Davi ...
- MRBS, meeting room manager system,会议预定管理系统
MRBS,会议管理软件,新增权限控制,周期性例会管理等. 下载地址 http://www.dotnetcms.org/mrbs/mrbs.rar
- WPA-PSK无线网络破解原理及过程(转)
本文将主要讲讲WPA-PSK类型的无线网络安全问题,首先我们看下802.11协议相关的基础知识. 802.11常见的几种认证方式: 1.不启用安全 2.WEP 3.WPA/WPA2-P ...
- spring4 security 4 +websocket 实现单点登录
测试地址:http://sms.reyo.cn/ 帐号:aa 密码:123456 先看一下效果图: spring4 security 4 实现单点登录,而websocket 实现单点的下线通知
- WindowsPhone-GameBoy模拟器开发六--[转]指令系统实现必读:补码
网上有同行写了些好文章,在此就不现丑了,贴上连接,放在这里为了补充系列的完整性 计算机为什么选用二进制补码 为什么补码重要?因为计算机中内存.寄存器里面存的数都是用补码表示的!
- eclipse快捷键调试总结【转】
http://www.cnblogs.com/yxnchinahlj/archive/2012/02/22/2363542.html (1)Ctrl+M --切换窗口的大小(2)Ctrl+Q --跳到 ...
- 【ASP.NET MVC 5】第27章 Web API与单页应用程序
注:<精通ASP.NET MVC 3框架>受到了出版社和广大读者的充分肯定,这让本人深感欣慰.目前该书的第4版不日即将出版,现在又已开始第5版的翻译,这里先贴出该书的最后一章译稿,仅供大家 ...