[CodeForces] 1016D Vasya And The Matrix

本文介绍了一种矩阵构造题的解决方法,对于给定的行和列的异或和,构造一个满足条件的矩阵,或者判断无法构造。通过特定的填充策略完成矩阵构造,并给出了具体的代码实现。

题目描述

Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!

Vasya knows that the matrix consists of n n n rows and m m m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1,a2,...,an a_{1},a_{2},...,a_{n} a1,a2,...,an denotes the xor of elements in rows with indices 1 1 1 , 2 2 2 , ..., n n n , respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1,b2,...,bm b_{1},b_{2},...,b_{m} b1,b2,...,bm denotes the xor of elements in columns with indices 1 1 1 , 2 2 2 , ..., m m m , respectively.

Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.

翻译:已知一个n×m的矩阵,每行每列元素的异或和,请构造一个满足要求的矩阵。若不存在,输出"NO",否则输出"YES"和矩阵。

输入输出格式

输入格式:

The first line contains two numbers n n n and $ m (2<=n,m<=100) $ — the dimensions of the matrix.

The second line contains n n n numbers $ a_{1},a_{2},...,a_{n} (0<=a_{i}<=10^{9}) $ , where ai a_{i} ai is the xor of all elements in row i i i .

The third line contains m m m numbers $ b_{1},b_{2},...,b_{m} (0<=b_{i}<=10^{9}) $ , where bi b_{i} bi is the xor of all elements in column i i i .

输出格式:

If there is no matrix satisfying the given constraints in the first line, output "NO".

Otherwise, on the first line output "YES", and then n n n rows of m m m numbers in each $ c_{i1},c_{i2},...\ ,c_{im} (0<=c_{ij}<=2·10^{9}) $ — the description of the matrix.

If there are several suitable matrices, it is allowed to print any of them.

输入输出样例

输入样例#1:
2 3
2 9
5 3 13
输出样例#1:
YES
3 4 5
6 7 8
输入样例#2:
3 3
1 7 6
2 15 12
输出样例#2:NO

题目解析

显然构造题啊,因为0 ^ n = n,所以手玩样例就可以发现我们只要最后一行填a[],最后一列填b[],其他全填0就好了。
这道题的难点在于处理角上的那个数(即a,b的交点),这个点暴力算出来就好了(b的异或和)。
至于无解的情况,我们用a的异或和 和 b的异或和向比较,如果不相等就无解了。
证明很简单,只要时刻记着0 ^ n = n就可以了。

Code

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

const int MAXN = 100 + 5;

int n,m;
int a[MAXN],b[MAXN];
int ans1,ans2;

int main() {
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;i++) {
        scanf("%d",&a[i]);
        ans1 ^= a[i];
    }
    for(int i = 1;i <= m;i++) {
        scanf("%d",&b[i]);
        ans2 ^= b[i];
    }
    if(ans1 ^ ans2) {
        printf("NO\n");
        return 0;
    } else printf("YES\n");
    for(int i = 1;i < n;i++) {
        for(int j = 1;j < m;j++) printf("0 ");
        printf("%d\n",a[i]);
    }
    for(int i = 1;i < m;i++) {
        printf("%d ",b[i]);
    }
    int ans = b[m];
    for(int i = 1;i < n;i++) ans ^= a[i];
    printf("%d",ans);
    return 0;
}

 

转载于:https://www.cnblogs.com/floatiy/p/9482959.html

在车辆工程中,悬架系统的性能评估和优化一直是研究的热点。悬架不仅关乎车辆的乘坐舒适性,还直接影响到车辆的操控性和稳定性。为了深入理解悬架的动态行为,研究人员经常使用“二自由度悬架模型”来简化分析,并运用“传递函数”这一数学工具来描述悬架系统的动态特性。 二自由度悬架模型将复杂的车辆系统简化为两个独立的部分:车轮和车身。这种简化模型能够较准确地模拟出车辆在垂直方向上的运动行为,同时忽略了侧向和纵向的动态影响,这使得工程师能够更加专注于分析与优化与垂直动态相关的性能指标。 传递函数作为控制系统理论中的一种工具,能够描述系统输入和输出之间的关系。在悬架系统中,传递函数特别重要,因为它能够反映出路面不平度如何被悬架系统转化为车内乘员感受到的振动。通过传递函数,我们可以得到一个频率域上的表达式,从中分析出悬架系统的关键动态特性,如系统的振幅衰减特性和共振频率等。 在实际应用中,工程师通过使用MATLAB这类数学软件,建立双质量悬架的数学模型。模型中的参数包括车轮质量、车身质量、弹簧刚度以及阻尼系数等。通过编程求解,工程师可以得到悬架系统的传递函数,并据此绘制出传递函数曲线。这为评估悬架性能提供了一个直观的工具,使工程师能够了解悬架在不同频率激励下的响应情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值