URAL 1614. National Project “Trams” 构造
来源:互联网 发布:练字软件手机软件 编辑:程序博客网 时间:2024/05/16 06:47
1614. National Project “Trams”
Time limit: 0.5 second
Memory limit: 64 MB
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
3
1 6 2 1 3 42 3 6 5 4 65 1 4 2 5 3
Problem Author: Alexander Ipatov (idea — Magaz Asanov)
Problem Source: The 12th Urals Collegiate Programing Championship, March 29, 2008
Problem Source: The 12th Urals Collegiate Programing Championship, March 29, 2008
Tags: tricky problem
)题意:
输出n行,每行2*n个数。要求这2*n个数字能 两两相邻。
做法:
因为相邻的一共有n*(n-1)/2 对, 而把2*n个数字 两两互连,也是 n*(n-1)/2 对,所以每两个数之间是不能重复相邻的。
所以两侧 肯定是 123456 ,各个数字都出现一遍。
构造的方法是看别人的,首尾互取,然后把数列往后推1格,再首尾互取。
以n=3为例:
123456,
首尾互取 162534 为第一行
234561
首尾互取 213645 为第二行
345612
首尾互取 324156 为第三行
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int N, M; int main() { int i, j, k; cin>>N; M = N*2; for (i = 0; i < N; ++i) { int now = i; for (j = 0; j < N; ++j) { printf("%d %d",(j+now)%M+1,(M-1-j+now)%M+1);if(j!=N-1)printf(" "); } puts(""); } return 0; }
0 0
- URAL 1614. National Project “Trams” 构造
- URAL 1614. National Project “Trams” (图论大YY)
- national
- 【构造】URAL 1979 Resources Distribution
- ural 1667 Square Country 3,构造
- URAL 1737 Mnemonics and Palindromes 3 构造
- 【构造】URAL 2004 Scientists from Spilkovo
- ural 2004. Scientists from Spilkovo 构造
- Illegal spices (URAL 1995 YY构造)
- URAL 1779 The Great Team 构造题
- Ural 2045 Richness of words(构造)
- URAL 1105 Observers Coloring (构造法)
- URAL 1995 Illegal spices 贪心构造
- Ural 1040 Airline Company(构造)
- NWP National Writing Project’s value both in English and in Chinese
- URAL
- 【ural】
- URAL
- 机器学习博客导航
- 深入理解Java String#intern() 内存模型
- 3N+1
- Android客户端性能测试(一):使用APT测试Android应用性能
- 机器学习入门资源不完全汇总
- URAL 1614. National Project “Trams” 构造
- 复制字符串中的n个字符到另一个字符串中
- 国外程序员整理的机器学习资源大全
- URAL-1329 Galactic History
- C语言助教题目代码部分
- 消除字符串中多余的空格
- 插入排序与选择排序
- smart学习
- poj 1523 SPF(无向图求关节点)