当前位置:网站首页>7 row K with the weakest combat effectiveness in the matrix
7 row K with the weakest combat effectiveness in the matrix
2022-07-27 11:09:00 【DHU yanghualin (UV allergy)】
7 The weakest in the matrix K That's ok
author : Turbo The time limit : 1S chapter : curriculum design
Problem description :
Give you a size of m * n Matrix mat, The matrix consists of a number of soldiers and civilians , Use them separately 1 and 0 Express .
Please return to the weakest in the matrix k Index of rows ( Line number ), Sort by weakest to strongest .
If the first i The number of soldiers in line is less than the number of j That's ok , Or two lines of soldiers in the same number but i Less than j, So we think the i The battle effectiveness of the line is better than the first j Row weakness .
Soldiers Always The front position in a row , in other words 1 Always in 0 Before .
Example 1:
Input :
5 5
1 1 0 0 0
1 1 1 1 0
1 0 0 0 0
1 1 0 0 0
1 1 1 1 1
3
Output :
2 0 3
explain :
The number of soldiers in each line :
That's ok 0 Yes 2 people
That's ok 1 Yes 4 people
That's ok 2 Yes 1 people
That's ok 3 Yes 2 people
That's ok 4 Yes 5 people
Sort these rows from the weakest to the strongest to get [2,0,3,1,4]
Example 2:
Input :
4 4
1 0 0 0
1 1 1 1
1 0 0 0
1 0 0 0
2
Output :
0 2
explain :
The number of soldiers in each line :
That's ok 0 Yes 1 people
That's ok 1 Yes 4 people
That's ok 2 Yes 1 people
That's ok 3 Yes 1 people
Sort these rows from the weakest to the strongest to get [0,2,3,1]
Enter description :
Enter several lines :
Enter two integers on the first line m and n, Represents the number of rows and columns of the matrix .
after m That's ok , Enter... On each line n It's an integer (0 or 1) Represents the elements of the matrix .
Enter an integer in the last line k(1 <= k <= m).
Tips :
2 <= n, m <= 100
1 <= k <= m
The elements of a matrix No 0 Namely 1
The output shows that :
Output one line k It's an integer , Each integer is followed by a space .
Input example :
4 4
1 0 0 0
1 1 0 0
1 0 0 0
1 1 1 0
3
Output example :
0 2 1
#include<iostream>
#include<algorithm>
using namespace std;
struct student
{
int line= -1;
int number= 0;
};
bool cmp(student x, student y)
{
if (x.number == y.number)
return x.line < y.line;
else
return x.number < y.number;
}
int main()
{
int arr[500][500];
student m[100];
int x = 0;
int y = 0;
cin >> x >> y;
for (int i = 0; i < x; i++)
{
m[i].line = i;
for (int u = 0; u < y; u++)
{
cin >> arr[x][u];
if (arr[x][u] == 1)
{
m[i].number++;
}
}
}
int k = 0;
cin >> k;
sort(m, m + x, cmp);
for (int i = 0; i < k; i++)
{
cout << m[i].line;
cout << " ";
}
return 0;
}边栏推荐
- Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?
- 华硕无双,这可能是屏幕最好的平价高刷轻薄笔记本
- ASP.NET Core依赖注入之旅:1.理论概念
- Neural network learning notes
- Set up Samba service
- Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
- Openldap custom schema
- 学习笔记-uni-app
- Substr and substring function usage in SQL
- 已解决SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated
猜你喜欢

ECCV 2022 | 同时完成四项跟踪任务!Unicorn: 迈向目标跟踪的大统一

SQL Server2000数据库错误

Play with the cluster configuration center and learn about the Taier console

一次跨域问题的记录

深度解析:什么是Diffusion Model?

Analysis of C language pointer function and function pointer

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

How to modify the strict mode under MySQL so that adding new users by inserting user table is successful

Yiwen counts NFT projects valued at more than US $100million

Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?
随机推荐
Internal and external troubles of digital collection NFT "boring ape" bayc
MIMO array 3D imaging technology based on mobile terminal
7z usage
Use kaggle to run Li Hongyi's machine learning homework
Tree data conversion
IO stream_ Overview and explanation of data input and output flow
Edata base, a secondary development project based on spark packaging, is introduced
Recruit top talents! The "megeagle creator program" of Kuangshi technology was officially launched
Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis
Distributed block device replication: client
Overview of radar communication integrated waveform design
Shortest moving distance and entropy of morphological complex
Error: image clipToBoundsAndScale, argument 'input'
[QNX hypervisor 2.2 user manual]9.9 logger
MySQL must know and know!!! Reading this article is enough!!!
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
神经网络学习笔记
Time and power allocation method to ensure fairness in sensor fusion system
Tcp/ip protocol
Use of pyquery