URAL 1933 Guns for Battle!

2024-05-28 10:48
文章标签 ural battle 1933 guns

本文主要是介绍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!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1010352

相关文章

ural 1297. Palindrome dp

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unli

ural 1149. Sinus Dances dfs

1149. Sinus Dances Time limit: 1.0 second Memory limit: 64 MB Let  An = sin(1–sin(2+sin(3–sin(4+…sin( n))…) Let  Sn = (…( A 1+ n) A 2+ n–1) A 3+…+2) An+1 For given  N print  SN Input One

ural 1820. Ural Steaks 贪心

1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered  n specialty steaks

ural 1017. Staircases DP

1017. Staircases Time limit: 1.0 second Memory limit: 64 MB One curious child has a set of  N little bricks (5 ≤  N ≤ 500). From these bricks he builds different staircases. Staircase consist

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

后缀数组 - 求最长回文子串 + 模板题 --- ural 1297

1297. Palindrome Time Limit: 1.0 second Memory Limit: 16 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlim

【HDU】3986 Harry Potter and the Final Battle 最短路

传送门:【HDU】3986 Harry Potter and the Final Battle 题目分析:先求一次最短路,同时记录在最短路上的顶点以及以该顶点为弧尾的最短路上的边。然后枚举删除每一条边,分别求一次最短路,其中最大的即答案。当然不可达输出-1。 测试发现堆优化的dij不如slf优化的spfa。。可能图太稀疏了吧。。。反正我觉得我写的挺搓的了。。。 代码如下:

【URAL】1057 Amount of Degrees 数位DP

传送门:【URAL】1057 Amount of Degrees 题目分析:将数转化成能达到的最大的01串,串上从右往左第i位为1表示该数包括B^i。 代码如下: #include <cstdio>#include <cstring>#include <algorithm>using namespace std ;typedef long long LL ;#de

1013. Battle Over Cities (25) DFs

1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is vitally important to have all the cities connected by highways in a