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 ...
随机推荐
- MySQL:InnoDB存储引擎的B+树索引算法
很早之前,就从学校的图书馆借了MySQL技术内幕,InnoDB存储引擎这本书,但一直草草阅读,做的笔记也有些凌乱,趁着现在大四了,课程稍微少了一点,整理一下笔记,按照专题写一些,加深一下印象,不枉读了 ...
- jQuery页面滚动监听事件及高级效果插件
jQuery页面滚动监听事件及高级效果插件 1. One Page scroll (只适用于上下焦点图)http://www.thepetedesign.com/demos/onepage_scrol ...
- Struts2入门3 深入学习
Struts2入门3 深入学习 处理结果和异常 前言: Struts学习的差不多了,还有最后的一点就收官了就是结果处理和异常处理.前面学习Struts主要围绕就是Action以及struts.xml配 ...
- android: UriMatcher的用法
ContentProvider是Android四大组件之一,网上也有不少关于它的文章,基本用法都可以查到,但关于UriMatcher在其中的作用,文章中都有例子,但我觉得还没有说清楚. 先说为什么用U ...
- Activiti 删除key值相同的所有不同版本的流程定义
package com.mycom.processDefinition; import java.io.File; import java.io.IOException; import java.io ...
- VS2010几款超赞的扩展辅助工具总结
详情请查看http://www.aehyok.com/Blog/Detail/72.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链 ...
- RTL8710 Flasher
https://bitbucket.org/rebane/rtl8710_openocd/ rtl8710_openocd / script / rtl8710.ocd # # OpenOCD scr ...
- ArrayList/Vector的原理、线程安全和迭代Fail-Fast
疑问 * ArrayList是非线程非安全的,具体是指什么?具体会产生什么问题?* ArrayList的内部原理是什么?为什么可以动态扩容?* Vector是线程安全的,具体是如何实现的?为什么不再推 ...
- Swift - UITableViewCell倒计时重用解决方案
Swift - UITableViewCell倒计时重用解决方案 效果 源码 https://github.com/YouXianMing/Swift-Animations // // CountDo ...
- vertex compression所遇到的问题
对于数据压缩,其实就是把浮点的32位精度,改用16位定点数来表达. 例如0.0 = 0,1.0 = 32767,-1.0 = -32767 这是一种有损压缩,会丢失一些精度,一般情况下是可以接受的. ...