传送门

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. poj2184 Cow Exhibition

    思路: dp+滚动数组. 类似01背包. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...

  2. android studio 定时器操作 实现定时执行相关任务

    package ipget.wenzheng.studio.ipget; import android.os.Bundle; import android.os.Handler; import and ...

  3. Makefile介绍

    make 工具如 GNU make.System V make 和 Berkeley make 是用来组织应用程序编译过程的基本工具,但是每个 make 工具之间又有所不同.不同的make工具的mak ...

  4. Unity3D windows平台视频录制录屏插件 UnityRecorder

    例子:从官方例子简单改了 using UnityEditor;using UnityEditor.Recorder;using UnityEditor.Recorder.Input;using Sys ...

  5. Zend Studio 修改“代码字体和大小”

  6. Selenium3+python自动化008-操作浏览器基本方法

    一.打开网站1.第一步:从selenium里面导入webdriver模块2.打开Firefox浏览器(Ie和Chrome对应下面的)3.打开百度网址二.页面刷新1.有时候页面操作后,数据可能没及时同步 ...

  7. 雷林鹏分享:Lua 数据类型

    Lua是动态类型语言,变量不要类型定义,只需要为变量赋值. 值可以存储在变量中,作为参数传递或结果返回. Lua中有8个基本类型分别为:nil.boolean.number.string.userda ...

  8. html5新增的定时器requestAnimationFrame

    在requestAnimationFrame出现之前,我们一般都用setTimeout和setInterval,那么html5为什么新增一个requestAnimationFrame,他的出现是为了解 ...

  9. dubbo负载均衡策略和集群容错策略

    dubbo负载均衡策略 random loadbalance 默认情况下,dubbo是random load balance随机调用实现负载均衡,可以对provider不同实例设置不同的权重,会按照权 ...

  10. Delete 语句带有子查询的sql优化

    背景: 接到开发通知,应用页面打不开,让我协助... (开发跟我说,表GV_BOOKS一直有锁,锁了有1个多小时了,问我能不能把锁释放掉,我回答他们说,这肯定是sql性能问题,表上有锁是正常现象,不是 ...