URAL 1933 Guns for Battle!
2015-09-05 17:27
393 查看
Will: Load the guns.
Annamaria: With what?
Will: Anything. Everything.
Gibbs: Anything we have left. Load the guns! Case shot and langrage. Nails and crushed glass.
“Black Pearl” always had some problems with discipline. It is known that you should start solving big problems from solving smaller ones, that is why, firstly, Joshami Gibbs decided to find out who is responsible for servicing
the guns during the battle.
It was pretty hard. There are n guns on the ship. All guns are quite heavy and difficult to use, so two gunners are necessary to serve one gun. Since there are 2
n + 1 gunners on board, one gunner has no pair in every battle. So, this pirate gets a role of commander during this battle.
Gibbs wants to make a schedule which will determine pairs of gunners and a commander for 2
n + 1 coming battles. Gibbs does not want the same pair of pirates to be on duty more than one time according the schedule because the pirates working in pairs bother each other. Moreover, if during 2
n + 1 battles one of the pirates is a commander twice or more, then Gibbs’s team will doubt in indifference of Gibbs, and it also leads to discipline problems. So many restrictions puzzled Joshami Gibbs. Help him make such schedule.
Input
The only line contains one integer n that is the number of gunners on board (1 ≤
n ≤ 100).
Output
Output 2 n + 1 lines each containing 2
n + 1 integers from 0 to 2 n + 1, j-th number in i-th line is equal to number of battle where gunners
i and j serve the gun together. Battles are numbered from 1.
i-th number in i-th line is 0.
Sample Input
给你2n+1个士兵 排成关于对角线对称的形式
Annamaria: With what?
Will: Anything. Everything.
Gibbs: Anything we have left. Load the guns! Case shot and langrage. Nails and crushed glass.
“Black Pearl” always had some problems with discipline. It is known that you should start solving big problems from solving smaller ones, that is why, firstly, Joshami Gibbs decided to find out who is responsible for servicing
the guns during the battle.
It was pretty hard. There are n guns on the ship. All guns are quite heavy and difficult to use, so two gunners are necessary to serve one gun. Since there are 2
n + 1 gunners on board, one gunner has no pair in every battle. So, this pirate gets a role of commander during this battle.
Gibbs wants to make a schedule which will determine pairs of gunners and a commander for 2
n + 1 coming battles. Gibbs does not want the same pair of pirates to be on duty more than one time according the schedule because the pirates working in pairs bother each other. Moreover, if during 2
n + 1 battles one of the pirates is a commander twice or more, then Gibbs’s team will doubt in indifference of Gibbs, and it also leads to discipline problems. So many restrictions puzzled Joshami Gibbs. Help him make such schedule.
Input
The only line contains one integer n that is the number of gunners on board (1 ≤
n ≤ 100).
Output
Output 2 n + 1 lines each containing 2
n + 1 integers from 0 to 2 n + 1, j-th number in i-th line is equal to number of battle where gunners
i and j serve the gun together. Battles are numbered from 1.
i-th number in i-th line is 0.
Sample Input
input | output |
---|---|
1 | 0 1 2 1 0 3 2 3 0 |
#include<stdio.h> #include<string.h> int main() { int n,i,j,a[300][300],z; while(~scanf("%d",&n)) { n=n*2+1; memset(a,0,sizeof a); int k=1; int l=2; for(i=2;i<=n;i++) { if(k>n) k=1; for(z=0;z<l;z++) { if(i-z==z+1) continue; a[i-z][z+1]=k; } l++; k++; } for(i=1;i<n;i++) { if(k>n) k=1; for(z=1;z<l;z++) { if(n-z+1==z+i) continue; a[n-z+1][z+i]=k; } // printf("%d %d\n",l,k); l--; k++; } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(j==1) printf("%d",a[i][j]); else printf(" %d",a[i][j]); } printf("\n"); } } return 0; }
相关文章推荐
- 倒置英文句子中单词的字母顺序
- mysql主主模式配置
- 游戏AI的综合设计
- JAVA-string类之compareTo用法
- android标识码
- Wireshark和TcpDump抓包分析心得
- Android 控件之二:TextView 文本框
- Goods:按bid查询返回desc.jsp页面详细信息
- YUM的工作机制与配置
- [NoSQL] 海量数据解决思路之Hash算法
- 嵌入式linux程序之调试方法
- AOI 服务器的实现
- 【JAVASCRIPT】ECMAScrip (转)
- Ashmem(匿名内存共享)
- 清除浮动
- HDU 4414 Finding crosses
- UITableView 的使用的小技巧
- 游戏的AOI算法
- 第五章 模版和Static Media
- object references an unsaved transient instance - save the transient instance before flushing