【51nod】1655 染色问题
题解
首先每个颜色出现的次数应该是一样的
\(\frac{C_{n}^{2}}{n} = \frac{n - 1}{2}\)
所以n如果是偶数那么就无解了
然后我们需要让每个点连颜色不同的四条边
只要端点是i,j,颜色是(i + j)%n就行
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <set>
//#define ivorysi
#define eps 1e-8
#define mo 974711
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define MAXN 30005
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
const int64 MOD = 1000000007;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
}
template<class T>
void out(T x) {
if(x < 0) {putchar('-');x = -x;}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
int N,T;
read(T);
while(T--) {
read(N);
out(N);putchar('\n');
if(N % 2 == 0) puts("No solution");
else {
for(int i = 1 ; i <= N ; ++i) {
for(int j = i + 1 ; j <= N ; ++j) {
out(i);space;out(j);space;
int x = (i + j) % N;if(x == 0) x = N;
out(x);space;
}
}
enter;
}
}
return 0;
}
【51nod】1655 染色问题的更多相关文章
- Good Vegetable 4级算法题 分值: [320/3120] 问题: [8/78]
1523 非回文 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 一个字符串是非回文的,当且仅当,他只由前p个小写字母 ...
- 【51nod】2564 格子染色
[51nod]2564 格子染色 这道题原来是网络流-- 感觉我网络流水平不行-- 这种只有两种选择的可以源点向该点连一条容量为b的边,该点向汇点连一条容量为w的边,如果割掉了b证明选w,如果割掉了w ...
- 51nod 算法马拉松18 A 染色问题
染色问题 基准时间限制:1 秒 空间限制:10240 KB 分值: 40 一个n(3<=n<=100)个点的完全图,现在给出n,要求将每条边都染上一种颜色k(1<=k<=n), ...
- 51nod 1448 二染色问题 (逆向考虑)
题目: 注意,这题不是把一块区域的黑翻成白.白翻成黑. 是把一块区域全部翻成白或者翻成黑. 初始为全白,看能否翻出题中的情况. 我们假设翻转若干次能得到图中的形状,那么我们找出最后一次的翻转,即全W或 ...
- 【51nod 1824】染色游戏
题目 有 n 个红球, m 个蓝球,从中取出 x 个红球和 y 个蓝球排成一排的得分是 rx⋅by ,其中 r0=b0=1 . 定义 f(t) 表示恰好取出 t 个球排成一排的所有可能局面的得分之和. ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
随机推荐
- JS获取FckEditor的值
不需要在页面引用任何额外的JS文件 //获取编辑器中HTML内容 function getEditorHTMLContents(EditorName) { var oEditor = FCKedito ...
- Interval GCD
题目描述 给定一个长度为N的数列A,以及M条指令 (N≤5*10^5, M<=10^5),每条指令可能是以下两种之一:“C l r d”,表示把 A[l],A[l+1],…,A[r] 都加上 d ...
- TPS低,CPU高--记一次storm压测问题排查过程
一.业务背景+系统架构 本次场景为kafka+storm+redis+hbase,通过kafka的数据,进入storm的spout组件接收,转由storm的Bolt节点进行业务逻辑处理,最后再推送进k ...
- 手机中的js事件
// 手势事件 touchstart //当手指接触屏幕时触发 touchmove //当已经接触屏幕的手指开始移动后触发 touchend //当手指离开屏幕时触发 touchcancel // 触 ...
- .net WebService 大数据量时性能的提高
1.直接返回DataSet对象 [WebMethod(Description = "直接返回DataSet对象")] public DataSet GetUserListDateS ...
- C++中的二级指针和指针引用函数传参
在函数的使用过程中,我们都明白传值和传引用会使实参的值发生改变.那么能够通过传指针改变指针所指向的地址吗? 在解决这个问题之前,也许我们应该先了解指针非常容易混淆的三个属性: ①.指针变量地址(&am ...
- static_cast、dynamic_cast、reinterpret_cast、和const_c
;double dval = 3.14159; ival + dval;//ival被提升为double类型 2)一种类型表达式赋值给另一种类型的对象:目标类型是被赋值对象的类型 int *pi = ...
- Linux USB驱动框架分析(2)【转】
转自:http://blog.chinaunix.net/uid-23046336-id-3243543.html 看了http://blog.chinaunix.net/uid-11848011 ...
- vm tools安装包为空
新装了linux mint虚拟机之后突然发现安装vm tools时为空 1.关闭虚拟机2.打开设置 3.把CD/DVD(SATA)从安装系统时挂载的镜像改为自动检测 4.重启安装vm tools发现没 ...
- Python之容器类Collections
容器类Collections 标签(空格分隔): Python进阶 defaultdict counter deque namedtuple defaultdict defaultdict的作用是可以 ...