传送门

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. canvas基础绘制-绚丽时钟

    效果图: 与canvas基础绘制-绚丽倒计时的代码差异: // var endTime = new Date();//const声明变量,不可修改,必须声明时赋值: // endTime.setTim ...

  2. Javaweb学习笔记9—过滤器

      今天来讲javaweb的第9阶段学习.   过滤器,我在本次的思维导图中将过滤器和监听器放在一起总结了,监听器比较简单就不单独写了.   老规矩,首先先用一张思维导图来展现今天的博客内容.     ...

  3. 项目中非常有用并且常见的ES6语法

    今天闲着无事,梳理下ES6常见的语法知识点:除此之外的知识点自行细化和梳理! <!DOCTYPE html> <html> <head> <meta char ...

  4. SQL数据库移植到ARM板步骤

    SQL作为一种存储数据的数据结构,具有体积小(能堵存储的数据多),容易移植等优点.例如,在Ubuntu或者ARM开发板上被大量应用.下面就简单说一下SQL移植到ARM板的步骤. 下载源代码 (记得在家 ...

  5. Unity复杂的旋转-欧拉角和四元数

    一.欧拉角欧拉角最容易表示,用三个变量X,Y,Z可以直观的表示绕着某个轴的旋转角度. 在Unity里就是Transform组件的Rotation里的X Y Z三个变量代表了欧拉角 二.四元数四元数相比 ...

  6. 递归的可视化(Fibonacci)

    递归的可视化 修改递归函数,使其能够显示打印出每次函数递归调用的形参的值. 每一级调用的输出都带有一级缩进,就是使得程序的输出清晰.有趣并且有含义. 思路 以斐波那契数列为例,假设n=5,递归的形参如 ...

  7. H5里div多行显示省略号

    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: ; overflow: hidden; -webkit- ...

  8. 一个Lucene.Net的Demo

    今天突然想来看一下全文检索,于是就了解了一下Lucene.Net,然后把公司目前的产品表拿来练手,写了这么个Demo. 先看一下Demo的代码 public class ProductReposito ...

  9. 目标检测中bounding box regression

    https://zhuanlan.zhihu.com/p/26938549 RCNN实际包含两个子步骤,一是对上一步的输出向量进行分类(需要根据特征训练分类器):二是通过边界回归(bounding-b ...

  10. Python List extend()方法

    Python List extend()方法  Python 列表 描述 extend() 函数用于在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表). 语法 extend()方法语法 ...