Codeforces Round #822 (Div. 2) - E. Rectangular Congruence

同余

Problem - E - Codeforces

题意

给一个长度为 n(2<=n<350) 的数组 bi, 0<=b0,b1...bn<n

要构造一个大小为 nn 的矩阵 A,ai,i=bi, 并且满足对于任意的 0<=r1<r2<n,0<=c1<c2<n, 有 Ar1,c1+Ar2,c2Ar1,c2+Ar2,c1(modn)

即任意一个子矩阵,满足在模 n 意义下,左上角 + 右下角 != 左下角 + 右上角

思路

可以将上述限制移项,得到 Ar1,c1Ar1,c2Ar2,c1Ar2,c2(modn)

即对于任意一个子矩阵,在模 n 意义下,左上角 - 右上角 != 左下角 - 右下角

因此只需要让每一行为公差不同的等差数列即可

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
#define endl "\n"

typedef long long ll;
typedef pair<int, int> PII;

const int N = 360;
int a[N][N];
int n;
int b[N];

void print()
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			cout << a[i][j] << " ";
		cout << endl;
	}
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			a[i][j] = (j - i) * i + b[i];
			a[i][j] = (a[i][j] % n + n) % n;
		}
	}
	print();
    return 0;
}
posted @   hzy0227  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
点击右上角即可分享
微信分享提示