URAL 1933 Guns for Battle!

给一个n,要求构造一个矩阵,满足:

1、矩阵大小为(2n+1)*(2n+1)

2、沿对角线对称

3、每个数的值在[0,2n+1]上

4、每行每列没有重复的值

手动写了一下 直接找到规律。。

#include<cstdio>
#include<cstring>
using namespace std;

int n,m,i,j,cnt,s[205][205],k;

int main()
{
    while(~scanf("%d",&n))
    {
        m=2*n+1;
        cnt=1;
        for(i=0;i<m;i++,cnt--)
        {
            if(cnt==-1) cnt=m-1;
            for(j=cnt,k=1;k<=m;j++,k++)
            {
                if(j==m) j=0;
                s[i][j]=k;
            }
            s[i][i]=0;
        }
        for(i=0;i<m;i++)
        {
            for(j=0;j<m-1;j++)
                printf("%d ",s[i][j]);
            printf("%d\n",s[i][m-1]);
        }
    }
    return 0;
}

URAL 1933 Guns for Battle!,布布扣,bubuko.com

时间: 2024-10-17 21:28:03

URAL 1933 Guns for Battle!的相关文章

URAL 1439. Battle with You-Know-Who treap树

题目来源:URAL 1439. Battle with You-Know-Who 题意:开始有数列1, 2, 3, ... L k输出第k大的数 D k删除第k大的数 思路:treap树插入删除的数 每次二分查找第k大的数为mid 查询treap小于等于mid的数有y个 那么mid应该是第mid-y大的数 与k比较 继续二分 #include <cstdio> #include <cstring> #include <cstdlib> #include <algo

(校赛)URAL 1991 The battle near the swamp

In the battle with the Trade Federation, Queen Amidala decided to ask gungans for help. Jar Jar Binks escorted the Queen and her people to the holy place where they had an agreement. The gungans agreed to provide their army in order to get the droids

URAL 1991. The battle near the swamp

1991. The battle near the swamp Time limit: 1.0 second Memory limit: 64 MB Gungan: Jar Jar, usen da booma! Jar Jar: What? Mesa no have a booma! Gungan: Here. Taken dis one. In the battle with the Trade Federation, Queen Amidala decided to ask gungans

URAL - 1785,1293,1877,1409,1820,1787,1264,2012

开始水URAL,今天先来几个.. 1785. Lost in Localization Time limit: 1.0 second Memory limit: 64 MB The Lavin Interactive Company, which has developed the turn-based strategy Losers-V, is constantly extending its target market by localizing the game to as many la

URAL 1873. GOV Chronicles

唔 神题一道 大家感受一下 1873. GOV Chronicles Time limit: 0.5 secondMemory limit: 64 MB A chilly autumn night. Well wrapped up in a coat, a man is rapidly walking along a gray street. This is the Tradition Keeper of the ACM club in Ural State University. Drizzl

NYOJ 284 坦克大战 &amp;&amp; POJ 2312 Battle City (广搜+优先队列)

链接:click here~~ 题意: 描述 Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this game. Given a map that consists of empty space

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

21 Guns -- Green Day

21 Guns Green Day (绿日乐队)的代表曲之一.歌曲的主题是反战,同时安慰了曾 经信任布什政府如今失望透顶的美国民众.这首歌也被电影<变形金刚2> 当作插曲. Do you know what's worth fighting for When it's not worth dying for? Does it take your breath away And you feel yourself suffocating1?Does the pain weigh out the

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀