题解

首先每个颜色出现的次数应该是一样的

\(\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 染色问题的更多相关文章

  1. Good Vegetable 4级算法题 分值: [320/3120] 问题: [8/78]

    1523 非回文 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 一个字符串是非回文的,当且仅当,他只由前p个小写字母 ...

  2. 【51nod】2564 格子染色

    [51nod]2564 格子染色 这道题原来是网络流-- 感觉我网络流水平不行-- 这种只有两种选择的可以源点向该点连一条容量为b的边,该点向汇点连一条容量为w的边,如果割掉了b证明选w,如果割掉了w ...

  3. 51nod 算法马拉松18 A 染色问题

    染色问题 基准时间限制:1 秒 空间限制:10240 KB 分值: 40 一个n(3<=n<=100)个点的完全图,现在给出n,要求将每条边都染上一种颜色k(1<=k<=n), ...

  4. 51nod 1448 二染色问题 (逆向考虑)

    题目: 注意,这题不是把一块区域的黑翻成白.白翻成黑. 是把一块区域全部翻成白或者翻成黑. 初始为全白,看能否翻出题中的情况. 我们假设翻转若干次能得到图中的形状,那么我们找出最后一次的翻转,即全W或 ...

  5. 【51nod 1824】染色游戏

    题目 有 n 个红球, m 个蓝球,从中取出 x 个红球和 y 个蓝球排成一排的得分是 rx⋅by ,其中 r0=b0=1 . 定义 f(t) 表示恰好取出 t 个球排成一排的所有可能局面的得分之和. ...

  6. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  7. 51Nod 1268 和为K的组合

    51Nod  1268  和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...

  8. 51Nod 1428 活动安排问题

    51Nod   1428  活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...

  9. 51Nod 1278 相离的圆

    51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...

随机推荐

  1. java io读写文件

    java io读写文件相关阅读:http://www.cnblogs.com/wing011203/archive/2013/05/03/3056535.html public class DemoI ...

  2. kibana做图表无法选取需要选的字段

    kibana做图表无法选取需要选的字段,即通过term的方式过滤选择某一个field时发现列表里无此选项. 再去discover里看,发现此字段前面带有问号,点击后提示这个字段未做索引,不能用于vis ...

  3. Nginx location 配置用法及正则例子

    Nginx location 配置语法     1. location [ = | ~ | ~* | ^~ ] uri { ... }     2. location @name { ... }   ...

  4. [洛谷P4492] [HAOI2018]苹果树

    洛谷题目链接:[HAOI2018]苹果树 题目背景 HAOI2018 Round2 第一题 题目描述 小 C 在自己家的花园里种了一棵苹果树, 树上每个结点都有恰好两个分支. 经过细心的观察, 小 C ...

  5. javascript iframe相关操作

    1. 获得iframe的window对象 iframeElement.contentWindow 2. 获得iframe的document对象 存在跨域访问限制. chrome:iframeEleme ...

  6. undefined reference to 'pthread_create'问题解决 -- 转

    文章出处:http://blog.csdn.net/llqkk/article/details/2854558 由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个 ...

  7. HDU 3449 Consumer (背包问题之有依赖背包)

    题目链接 Problem Description FJ is going to do some shopping, and before that, he needs some boxes to ca ...

  8. Linux基础-swap交换分区

    任务:对一块15G大小的硬盘进行分区,主分区为5G,扩展分区10G,一个逻辑分区5G作为swap交换分区,并激活查看新的swap分区 第一步,建立的新的SCSI硬盘,开启Linux系统前添加一块大小为 ...

  9. linux tar 解压出错

    今天用tar -xzvf php-7.2.3.tar.gz 解压php的tar包时报错 [root@VM_72_37_centos ~]# tar -xzvf php-.tar.gz gzip: st ...

  10. 原生的js实现jsonp的跨域封装

    一.原理 jsonp是利用浏览器请求script文件时不受同源策略的限制而实现的,伪造一个script标签,将请求数据的url赋值给script的src属性,并将该标签添加到html中,浏览器会自动发 ...