CF-12E - Start of the season(思维)
来源:互联网 发布:软件性能参数 编辑:程序博客网 时间:2024/05/23 14:01
Crawling in process...Crawling failedTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Before the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the sizen × n (n is even number). Gods will never allow to start the championship without it. Matrix should contain integers from0 to n - 1, main diagonal should contain only zeroes and matrix should be symmetric. Moreover, all numbers in each row should be different. Magicians are very tired of the thinking process, so they ask you to write a program to find such matrix.
Input
The first line contains one integer n (2 ≤ n ≤ 1000),n is even.
Output
Output n lines with n numbers each — the required matrix. Separate numbers with spaces. If there are several solutions, output any.
Sample Input
2
0 11 0
4
0 1 3 21 0 2 33 2 0 12 3 1 0
思路:每次错1位可以保证每一行都不同。而对称怎么解决呢?先不管0
弄成n-1维其符合题目条件的就很容易做到了。看例子:
输入为6
则不管0 错1位构造为
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
符合题目中的意思吧。现在吧0放到对角线上,并且把对角线上的数加到两边仍然符合要求。到这答案就出来了。
1 2 3 4 5 0 0 2 3 4 5 1
2 3 4 5 1 0 2 0 4 5 1 3
3 4 5 1 2 0 3 4 0 1 2 5
4 5 1 2 3 0 -> 4 5 1 0 3 2
5 1 2 3 4 0 5 1 2 3 0 4
0 0 0 0 0 0 1 3 5 2 4 0
1 2 3 4 5 0 0 2 3 4 5 1
2 3 4 5 1 0 2 0 4 5 1 3
3 4 5 1 2 0 3 4 0 1 2 5
4 5 1 2 3 0 -> 4 5 1 0 3 2
5 1 2 3 4 0 5 1 2 3 0 4
0 0 0 0 0 0 1 3 5 2 4 01 2 3 4 5 0 0 2 3 4 5 1
2 3 4 5 1 0 2 0 4 5 1 3
3 4 5 1 2 0 3 4 0 1 2 5
4 5 1 2 3 0 -> 4 5 1 0 3 2
5 1 2 3 4 0 5 1 2 3 0 4
0 0 0 0 0 0 1 3 5 2 4 01 2 3 4 5 0 0 2 3 4 5 1
2 3 4 5 1 0 2 0 4 5 1 3
3 4 5 1 2 0 3 4 0 1 2 5
4 5 1 2 3 0 -> 4 5 1 0 3 2
5 1 2 3 4 0 5 1 2 3 0 4
0 0 0 0 0 0 1 3 5 2 4 0
#include<iostream>#include<cstring>using namespace std;const int mm=1007;int map[mm][mm];int n;int main(){ while(cin>>n) { n--; memset(map,0,sizeof(map)); for(int i=0;i<n;i++) for(int j=0;j<n;j++) map[i][j]=(i+j)%n+1; for(int i=0;i<n;i++) map[i][n]=map[n][i]=map[i][i],map[i][i]=0; for(int i=0;i<=n;i++) {cout<<map[i][0]; for(int j=1;j<=n;j++) { cout<<" "<<map[i][j]; } cout<<"\n"; } }}
- CF-12E - Start of the season(思维)
- CF 12E Start of the season
- Codeforces 12E Start of the season
- Codeforces 12E Start of the season 构造 一个n*n矩阵使得每行恰好有一个[0,n-1]且对称
- codeforces 12E - Start of the session
- The summary of competition season
- CF-27E - Number With The Given Amount Of Divisors(枚举+dfs)
- CF 27E Number With The Given Amount Of Divisors
- (CF 792E Colored Balls) 思维题 贪心
- CF#804 B. Minimum number of steps(字符串,思维)
- Words of the Start
- CF Trainings Season 1 Episode 6 I (dp)
- cf(思维题)
- cf(思维,数学)
- CF 277 Div2 E LIS of Sequence
- cf 486E LIS of Sequence
- cf #310 E. Case of Chocolate (upper_bound())
- [CF 555E] Case of Computer Network
- 简易OA漫谈之工作流设计(DB)2
- 一些常见的树, 图的计数的问题
- memset()函数
- 对美国货币政策几个最常见的误读
- 探索Lua5.2内部实现:虚拟机指令(5)Arithmetic
- CF-12E - Start of the season(思维)
- jquery.valid 注册验证
- uart 串口控制器 驱动 s3c2410
- UT-Exynos4412 三星ARM四核旗舰开发平台android4.0体验-13串口功能调试
- CUSTOMER INTERFACE STATUS ERROR CODES
- 简易OA漫谈之工作流设计(DB实现)
- Android系统SVC命令(命令行WIFI开关、GPRS移动数据开关)
- Oracle数据导入导出imp/exp命令 10g以上expdp/impdp命令
- HDOJ 【C】 2007 平方和与立方和