传送门

1614. National Project “Trams”

Time limit: 0.5 second
Memory limit: 64 MB
President has declared the development of tram service a priority national project. As a part of this project, Yekaterinburg will receive enough budget funds to carry out a complete reconstruction of the city's tram network.
There are 2n tram stops in Yekaterinburg. In the course of reconstruction, the stops will be left in their places and no new stops will be built, but new tram railways will be laid so that it will be possible to go by tram from every tram stop to any other tram stop without any intermediate stops.
Having studied messages at the tram forum, the city authorities found out that citizens would be satisfied with the reconstruction only if for every pair of tram stops there would be a tram route connecting these stops without any intermediate stops. It is clear that the network of n(2n − 1) routes consisting of only two stops each satisfies this requirement. However, Yekaterinburg Mayor wants exactly n routes to be left after the reconstruction, and each tram must make exactly 2n stops (including the final ones) on its route. Trams must go along these routes in both directions. Suggest a plan of reconstruction that will satisfy both citizens and Mayor.

Input

The only input line contains the integer n, 1 ≤ n ≤ 100.

Output

Output n lines describing tram routes. Each route is a sequence of integers in the range from 1 to 2n separated by a space. A route may go through a stop several times. If the problem has several solutions, you may output any of them. If there is no solution, output one line containing the number −1.

Sample

input output
3
1 6 2 1 3 4
2 3 6 5 4 6
5 1 4 2 5 3
Problem Author: Alexander Ipatov (idea — Magaz Asanov)
Problem Source: The 12th Urals Collegiate Programing Championship, March 29, 2008

题意:

1-2*n个车站,两两之间要连一条边,即  2*n*(2*n-1)/2条边。

现在让你设计n条路线,每个路线包括2*n个车站,即每条路线你能连出2*n-1条边。

求一种满足题意的设计方案。

题解:

一开始试图设计如:

1 2 3 4 5 6

2 4 6 1 3 5

3 6 2 5 1 4

的设计,不过,在n=4的时候就蹦了。

找了好久的规律,设计出如:

1 6 2 5 3 4

2 1 3 6 4 5

3 2 4 1 5 6

的设计,就能满足所有条件了。  (第一次从 1 2 3 4 5 6取首尾首尾,第二次 从 2 3 4 5 6 1 取首尾首尾。。。)

6160974 16:53:31
16 Mar 2015
njczy2010 1614. National Project “Trams” G++ 4.9 Accepted   0.046 414 KB
 #include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string> #define ll long long
int const N = ;
int const M = ;
int const inf = ;
ll const mod = ; using namespace std; int n;
int ans[N][*N];
int b[N][*N]; void ini()
{
int i,j;
int p=*n;
for(i=;i<=n;i++){
for(j=;j<=*n;j++){
b[i][j]=(i+j-)%p;
if(b[i][j]==){
b[i][j]=p;
}
}
}
/*
printf(" b\n");
for(i=1;i<=n;i++){
printf("%d",b[i][1]);
for(j=2;j<=2*n;j++){
printf(" %d",b[i][j]);
}
printf("\n");
}*/
} void solve()
{
int i,j;
for(i=;i<=n;i++){
for(j=;j<=*n;j++){
ans[i][j]=b[i][j/+];
j++;
ans[i][j]=b[i][*n-j/+];
}
} } void out()
{
int i,j;
for(i=;i<=n;i++){
printf("%d",ans[i][]);
for(j=;j<=*n;j++){
printf(" %d",ans[i][j]);
}
printf("\n");
}
} int main()
{
// freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(cnt=1;cnt<=T;cnt++)
while(scanf("%d",&n)!=EOF)
{
ini();
solve();
out();
}
}

URAL 1614. National Project “Trams” [ 构造 欧拉回路 ]的更多相关文章

  1. URAL 1614. National Project “Trams” (图论大YY)

    1614. National Project "Trams" Time limit: 0.5 second Memory limit: 64 MB President has de ...

  2. CF527E Data Center Drama(构造+欧拉回路)

    题目链接 大意: 给你一个无向图. 要求加最少的边,然后给这些无向图的边定向,使得每一个点的出入度都是偶数. 输出定向后的边数和边集. n<=10^5 m<=2*10^5 很巧妙的构造题- ...

  3. hdu 4850 字符串构造---欧拉回路构造序列 递归+非递归实现

    http://acm.hdu.edu.cn/showproblem.php? pid=4850 题意:构造长度为n的字符序列.使得>=4的子串仅仅出现一次 事实上最长仅仅能构造出来26^4+4- ...

  4. Codeforces.209C.Trails and Glades(构造 欧拉回路)

    题目链接 \(Description\) 给定一张\(n\)个点\(m\)条边的无向图,允许有自环重边.求最少加多少条边后,其存在从\(1\)出发最后回到\(1\)的欧拉回路. 注意,欧拉回路是指要经 ...

  5. URAL 1995 Illegal spices 贪心构造

    Illegal spices 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1995 Description Jabba: Han, m ...

  6. [CF1303B] National Project - 数学

    Solution \(2a>n\),一次性结束,直接输出 \(n\) \(a \geq b\),那么一直修即可,直接输出 \(n\) 否则,\(a\) 占弱势,我们考虑用 \(a\) 修一半需要 ...

  7. Educational Codeforces Round 82 B. National Project

    Your company was appointed to lay new asphalt on the highway of length nn. You know that every day y ...

  8. Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路

    Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xx ...

  9. 关于aggregation 语法和表达式大全(最新3.4版)

    用mongodb四年多了,从1.8版用到目前的3.4版,功能越来越强大,而且它的每一次升级带给我的都是惊喜,最近发现他的aggregation(管道)技术越来越丰富了,基本上将它提供的所有功能都集成了 ...

随机推荐

  1. 手把手教写devops全栈自动化工具(django2.1)

    简单介绍一下自己之前写的一个全栈项目,框架用的是django2.1版本 主要对paramiko模块,salstack的API二次开发. 核心组件包括:MQ,mysql,websocket,redis, ...

  2. 磁盘格式化mke2fs

    -b 设置每个块的大小,当前支持1024,2048,40963种字节 -i 给一个inode多少容量 -c 检查磁盘错误,仅执行一次-c时候,会进行快速读取测试:-c -c会测试读写,会很慢 -L 后 ...

  3. 洛谷 P1011 车站

    题目描述 火车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上.下车,但上.下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人.从第3站起( ...

  4. PHP20 PHP面向对象辅助

    学习要点 常用函数 命名空间 类的自动加载 常用函数 class_exists 作用:检查类是否已定义 语法格式: bool class_exists ( string $class_name [, ...

  5. 用户管理命令--passwd,usermod,userdel

    用户修改密码命令--passwd 当修改用户的密码时,也要分普通用户和超级用户两种情况 普通用户:修改密码前需要先输入当前密码,确认是否正确 密码设置不可以过于简单 超级用户:权利非常的大,可以设置任 ...

  6. MariaDB数据库(二)

    1. MariaDB数据类型 MariaDB数据类型可以分为数字,日期和时间以及字符串值. 使用数据类型的原则:够用就行,尽量使用范围小的,而不用大的. 1.1  常用的数据类型 整数:int,bit ...

  7. 解决sqlplus无法退格问题

      # wget http://download.openpkg.org/components/cache/rlwrap/rlwrap-0.42.tar.gz # tar -zxf rlwrap-0. ...

  8. webpack 之 缓存处理

    针对 这里 的所提到的观点,如果webpack每次都生成相同名字的bundle.js,会导致问题.这里使用webpack的文件hash功能来解决,简简单单地为输出文件添加一个“[hash]”即可. / ...

  9. Java:清空文件内容

    文章来源:https://www.cnblogs.com/hello-tl/p/9139432.html import java.io.*; public class FileBasicOperati ...

  10. LeetCode(171) Excel Sheet Column Number

    题目 Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, re ...