当前位置:网站首页>Detailed explanation of Niuke - Gloves
Detailed explanation of Niuke - Gloves
2022-04-23 16:42:00 【Grow up, Leslie】
Original link : glove __ Cattle from
Their thinking :
1. First of all, consider that there are no gloves on both sides 0 The situation of
Take the one on the left as an example : Subtract the minimum number of colors from the number of all gloves on the left, and then +1, The above figure is the corresponding figure 17-2+1=16 only , in other words , Take... On the left 16 Gloves , sure Take out all the colors , Now just take one from the other hand and you can match it . Suppose to take 15 Gloves , Then there may be such a situation : Take it 4 Only yellow ,5 Only green ,6 Only blue ; Then you may not get the orange one , So take 15 A glove cannot 100% Take out all possible colors . Do the same for the one on the right , Judge which one is smaller on the left and right , Then the last value +1 It'll match .
2. There may be... On both sides 0 The situation of
The final code implementation :
class Gloves {
public:
int findMinimum(int n, vector<int> left, vector<int> right) {
// write code here
int sum=0;
int left_min=INT_MAX;
int right_min=INT_MAX;
int left_sum=0,right_sum=0;
for(int i=0;i<n;i++)
{
if(left[i]*right[i]==0)
sum+=left[i]+right[i];// If there is one for 0, We need to find out this situation
else
{
left_sum+=left[i];
left_min=left[i]<left_min?left[i]:left_min;
right_sum+=right[i];
right_min=right[i]<right_min?right[i]:right_min;
}
}
return sum+=(left_sum>right_sum?(right_sum-right_min+1):(left_sum-left_min+1))+1;
}
};
版权声明
本文为[Grow up, Leslie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231637283768.html
边栏推荐
- PHP 零基础入门笔记(13):数组相关函数
- Nacos 详解,有点东西
- The font of the soft cell changes color
- LVM and disk quota
- Force buckle - 198 raid homes and plunder houses
- ESXi封装网卡驱动
- 最详细的背包问题!!!
- Postman batch production body information (realize batch modification of data)
- Construction of promtail + Loki + grafana log monitoring system
- True math problems in 1959 college entrance examination
猜你喜欢
Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
How to build tiktok user trust and drive fan growth
PyMySQL
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
信息摘要、数字签名、数字证书、对称加密与非对称加密详解
NVIDIA graphics card driver error
Change the icon size of PLSQL toolbar
[pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return
Summary according to classification in sail software
How to choose the wireless gooseneck anchor microphone and handheld microphone scheme
随机推荐
loggie 源码分析 source file 模块主干分析
File system read and write performance test practice
About background image gradient()!
Gartner announces emerging technology research: insight into the meta universe
文件操作详解(2)
MySQL master-slave replication
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
How does flash cache data in memory?
信息摘要、数字签名、数字证书、对称加密与非对称加密详解
1959年高考数学真题
Pytorch: the pit between train mode and eval mode
Introduction to how to set up LAN
最详细的背包问题!!!
Derivation of Σ GL perspective projection matrix
文件系统读写性能测试实战
RAID磁盘阵列与RAID5的创建
File upload and download of robot framework
Dlib of face recognition framework
Change the icon size of PLSQL toolbar