当前位置:网站首页>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;
}边栏推荐
- 如何组装一个注册中心
- Deep analysis: what is diffusion model?
- Application scenarios, key technologies and network architecture of communication perception integration
- FAQs of "relay chain" and "dot" in Poka ecosystem
- Research on synaesthesia integration and its challenges
- 正则form表单判断
- 学习笔记-uni-app
- Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review
- Using skills of word
- Redis+caffeine two-level cache enables smooth access speed
猜你喜欢

Tdengine business ecosystem partner recruitment starts

Set up Samba service

WebRTC实现简单音视频通话功能

Non progressive phenomena of entropy and morphology

迭代次数和熵之间关系的一个验证试验

涌现与形态的局部差异和整体差异
![Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.](/img/7f/f42f9267cdff35522c260ef073bab9.png)
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.

Analysis of C language pointer function and function pointer

荒野觅踪---寻找迭代次数

Kangaroo cloud stack based on CBO in spark SQL optimization
随机推荐
Compete for the key battle of stock users and help enterprises build a perfect labeling system - 01 live review
Shortest moving distance and entropy of morphological complex
The open source project Taier version 1.1 was officially released, and the list of new functions is fast
pyquery 的使用
antd table中排序th阻止悬停变色+table悬停行变色+table表头变色
SQL Server2000 database error
antd中table hover上去的背景色样式修改
学习笔记-微信支付
The difference between scalar, vector, matrix and tensor in deep learning
神经网络学习笔记
ECCV 2022 | complete four tracking tasks at the same time! Unicorn: towards the unification of target tracking
泰山OFFICE技术讲座:缩放比例与打开文件
Google browser screenshot tips
TensorFlow笔记——基本函数及概念
Local and overall differences between emergence and morphology
Ten year structure five year life-07 young and vigorous transformation
Play with the cluster configuration center and learn about the Taier console
Object array de duplication
Learning notes - wechat payment
Regular form form judgment