您的位置:首页
URAL 1614. National Project “Trams” (图论大YY)
2017-06-17 11:59
302 查看
1614. National Project “Trams”
Time limit: 0.5 secondMemory 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 problemhas 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 |
Problem Source: The 12th Urals Collegiate Programing Championship, March 29, 2008
Tags: tricky problem (
hide tags for unsolved problems
)
Difficulty: 731 Printable version Submit solution Discussion
(4)
My submissions All submissions (1014) All
accepted submissions (481) Solutions rating (383)
题意:有N=2*n阶全然图,找n条路径,每条路径有2*n-1条边。正好n条路组成了全然图
思路:YY,每一个顶点的入度为N-1奇数,所以他们要分别做端点一次。分别做中间点n次
所以按端点对称构造路径,比方N=6,分别以(1,4)(2,6)(3。5)作对称点。这样3条路径的形状都一样
没条路再经过其它点各一次就可以。比方构造出:1->2->6->3->5->4这样的交错形状的路径,构造方式不止一种
#include<cstdio> #include<iostream> #include<iostream> #include<cstring> using namespace std; int path[110]; //构造一条形状同样的路径 int main() { int n; while(~scanf("%d",&n)) { int t=2*n+2,cnt=0,l=1; //对称构造 while(cnt!=2*n) { path[++cnt]=((t-l)-1)%(2*n)+1; path[++cnt]=++l; } //输出 for(int i=1;i<=n;i++) for(int j=1;j<=2*n;j++) { printf("%d%c",(path[j]+i-2)%(2*n)+1,j==2*n? '\n':' '); } } return 0; }
大神的构造方法:
#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; printf("%d", now+1); for (j = 1; j < M; ++j) { now = (now+j)%M; printf(" %d", now+1); } puts(""); } return 0; }
相关文章推荐
- URAL 1614. National Project “Trams” (图论大YY)
- URAL 1614. National Project “Trams” 构造
- URAL 1614. National Project “Trams” [ 构造 欧拉回路 ]
- 简单图论 ural 1779. The Great Team
- Failed to execute goal on project tanliu: Could not resolve dependencies for project com.yy.tanliu:t
- 263D - Cycle in Graph 图论 YY
- 002医疗项目-主工程模块yycgproject三层构建(三大框架的整合)
- QTMySqlIpInFpxShyyJuneEgyptProject
- Illegal spices (URAL 1995 YY构造)
- NWP National Writing Project’s value both in English and in Chinese
- 我的2016代码自动生成器--IoRyYBigProject
- URAL 1557 Network Attack 图论,连通性,tarjain,dfs建树,分类讨论 难度:2
- 【图论】Ural 1557
- 【图论】【二分图匹配】[Ural 1109]Conference
- 主工程模块yycgproject三层构建
- ssl1614-医院设置【图论,最短路】
- POJ 图论____简言
- URAL 1774 Barber of the Army of Mages 最大流
- project之间的关系
- [BZOJ2820]YY的GCD 莫比乌斯反演