当前位置:网站首页>2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
2022-04-23 03:22:00 【再敲一行就去睡】
给定一个 n×n 的整数矩阵。对任一给定的正整数 k<n,我们将矩阵的偶数列的元素整体向下依次平移 1、……、k、1、……、k、…… 个位置,平移空出的位置用整数 x 补。你需要计算出结果矩阵的每一行元素的和。
输入格式:
输入第一行给出 3 个正整数:n(<100)、k(<n)、x(<100),分别如题面所述。
接下来 n 行,每行给出 n 个不超过 100 的正整数,为矩阵元素的值。数字间以空格分隔。
输出格式:
在一行中输出平移后第 1 到 n 行元素的和。数字间以 1 个空格分隔,行首尾不得有多余空格。
输入样例:
7 2 99
11 87 23 67 20 75 89
37 94 27 91 63 50 11
44 38 50 26 40 26 24
73 85 63 28 62 18 68
15 83 27 97 88 25 43
23 78 98 20 30 81 99
77 36 48 59 25 34 22
输出样例:
440 399 369 421 302 386 428
样例解读
需要平移的是第 2、4、6 列。给定 k=2,应该将这三列顺次整体向下平移 1、2、1 位(如果有更多列,就应该按照 1、2、1、2 …… 这个规律顺次向下平移),顶端的空位用 99 来填充。平移后的矩阵变成:
11 99 23 99 20 99 89
37 87 27 99 63 75 11
44 94 50 67 40 50 24
73 38 63 91 62 26 68
15 85 27 26 88 18 43
23 83 98 28 30 25 99
77 78 48 97 25 81 22
一次到位,不容易超时
#include <bits/stdc++.h>
using namespace std;
int main(void){
int n,k,x,**p,*q;
cin>>n>>k>>x;
p=(int**)malloc(sizeof(int*)*n);
q=(int*)malloc(sizeof(int)*n);
for(int i=0;i<n;i++){
q[i]=0;
p[i]=(int*)malloc(sizeof(int)*n);
}
for(int i=0;i<n;i++){
for(int s,j=0;j<n;j++){
cin>>s;
if(j%2){
int t=(j/2)%k+1;
if(i<t)p[i][j]=x;
if(i+t<n)p[i+t][j]=s;
}
else p[i][j]=s;
q[i]+=p[i][j];
}
}
for(int i=0;i<n;i++){
if(i)cout<<' ';
cout<<q[i];
}
}
版权声明
本文为[再敲一行就去睡]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46212625/article/details/124349147
边栏推荐
- Supersocket is Use in net5 - concept
- Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer
- Mysql database
- socket編程 send()與 recv()函數詳解
- C-10 program error correction (recursive function): number to character
- New ORM framework -- Introduction to beetlsql
- Test experience data
- Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
- Blazor University (12) - component lifecycle
- Cefsharp stores cookies and reads cookies
猜你喜欢
可以接收多種數據類型參數——可變參數
General testing technology [1] classification of testing
Fiddler use
Eight elder brothers chronicle [4]
【无标题】
一套组合拳,打造一款 IDEA 护眼方案
MySQL query specifies that a row is sorted to the first row
. net 5 Web custom middleware implementation returns the default picture
Super easy to use [general excel import function]
MySQL之explain关键字详解
随机推荐
be based on. NETCORE development blog project starblog - (2) environment preparation and creation project
Flink实时数仓项目—DWS层设计与实现
[Mysql] LEFT函数 | RIGHT函数
Preview of converting doc and PDF to SWF file
. net 5 Web custom middleware implementation returns the default picture
When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
可以接收多種數據類型參數——可變參數
Data mining series (3)_ Data mining plug-in for Excel_ Estimation analysis
为什么BI对企业这么重要?
The most easy to understand service container and scope of dependency injection
C WPF UI framework mahapps switching theme
Log4net is in Net core usage
集合之List接口
Using jsonserialize to realize data type conversion gracefully
Is it difficult to choose binary version control tools? After reading this article, you will find the answer
Xamarin effect Chapter 22 recording effect
. NETCORE sets the API post mode, which can accept parameters directly in parentheses
MySQL grouping query rules
Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types