您的位置:首页 > 其它

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

inputoutput
1

0 1 2
1 0 3
2 3 0

给你2n+1个士兵 排成关于对角线对称的形式

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: