当前位置:网站首页>9 无人机方阵
9 无人机方阵
2022-07-17 00:07:00 【DHU杨骅麟(紫外线过敏)】
9 无人机方阵
作者: Turbo时间限制: 1S章节: 课程设计
问题描述 :
在 「挑战赛」 开幕式的压轴节目 「无人机方阵」中,每一架无人机展示一种灯光颜色。 无人机方阵通过两种操作进行颜色图案变换:
(1) 调整无人机的位置布局
(2) 切换无人机展示的灯光颜色
给定两个大小均为 N*M 的二维数组 source 和 target 表示无人机方阵表演的两种颜色图案,由于无人机切换灯光颜色的耗能很大,请返回从 source 到 target 最少需要多少架无人机切换灯光颜色。
注意: 调整无人机的位置布局时无人机的位置可以随意变动。
示例 1:
输入:
2 2
1 3
5 4
3 1
6 5
输出:1
解释:
第一行输入2 2表示方阵为2行2列,后面跟着的两行为source,再两行为target。
最佳方案为
将 [0,1] 处的无人机移动至 [0,0] 处;
将 [0,0] 处的无人机移动至 [0,1] 处;
将 [1,0] 处的无人机移动至 [1,1] 处;
将 [1,1] 处的无人机移动至 [1,0] 处,其灯光颜色切换为颜色编号为 6 的灯光;
因此从source 到 target 所需要的最少灯光切换次数为 1。
示例 2:
输入:
2 3
1 2 3
3 4 5
1 3 5
2 3 4
输出:0
解释:
仅需调整无人机的位置布局,便可完成图案切换。因此不需要无人机切换颜色
输入说明 :
输入若干行:
第一行为两个整数n和m,n代表二维数组的行数,m代表二维数组的列数。
而后n行,每行输入m个整数,代表source数组的元素。
再n行,每行输入m个整数,代表target数组的元素。
提示:
1 <= n, m <=100
1 <= source[i][j], target[i][j] <=10^4
输出说明 :
输出一个整数表示结果。
输入范例 :
3 3
4 5 2
2 3 4
7 8 3
3 5 8
3 7 3
7 1 9
输出范例 :
4
#include<iostream>
using namespace std;
int check(int a[][100], int b[][100],int m,int n)
{
int arr[10000] = {0};
for(int i=0;i<m;i++)
for (int j = 0; j < n; j++)
{
arr[a[i][j]]++;
}
for(int i=0;i<m;i++)
for (int j = 0; j < n; j++)
{
arr[b[i][j]]--;
}
int result = 0;
for (int u = 0; u < 10000; u++)
{
if(arr[u]>0)
result += arr[u];
}
return result;
}
int main()
{
int source[100][100] = { 0 };
int target[100][100] = { 0 };
int m = 0;
int n = 0;
cin >> m;
cin >> n;
for(int i=0;i<m;i++)
for (int u = 0; u < n; u++)
{
cin >> source[i][u];
}
for(int i=0;i<m;i++)
for (int u = 0; u < n; u++)
{
cin >> target[i][u];
}
cout<<check(source, target, m, n);
return 0;
}边栏推荐
- 02_ Data binding
- Uni app wechat applet - Mall (3) - Mall Homepage
- 自己封裝的風格化的開關卡片組件
- [elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]
- V-cloak and v-bind bind bind classes
- JS get the suffix format of a file name
- 红日安全靶场3
- 2022年暑假ACM热身练习2(总结)
- 08-BTC-分叉
- v-on的修饰符
猜你喜欢
随机推荐
今天的码农女孩做了关于生命周期的笔记以及动态时钟的练习
uni-app微信公众号(5)——新增、修改地址
openGauss内核分析-统计信息与行数估计
El form special character verification
Modifier of v-on
2022年暑假ACM热身练习2(总结)
Understand PHP from [Fifth space 2021] easycleanup_ session
ES6 syntax -- Deconstruction assignment
iptables和snort基本配置
Router and keep alive
How does the website count the number of visitors? How to install and use 51la?
Uni app wechat applet - Mall (6) - my home page
今天的码农女孩学习了关于事件操作和ref属性的笔记并做了表单双向绑定的练习
Es optional chain
Text indent in uniapp doesn't work, and the indentation in the first line of uniapp doesn't work. How to solve it?
Colorful text advertising code, text advertising code beautification version, add text advertising tutorials to the website
Cve-2022-34265 Django extract & TRUNC SQL injection vulnerability recurrence
uni-app微信小程序——商城(8)——订单详情
2022.7.7 一些错误总结
Uni block button multiple clicks button multiple clicks








