9-1腾讯笔试 前端
1.奇数=奇数+偶数,所以把第一列的奇数和偶数计数为cnt11,cnt12,第二列的奇数和偶数计数为cnt21,cnt22,结果为min(cnt11,cnt22)+min(cnt12,cnt21);
2.判断闰年,自己百度吧,,
3.递归解构
function flatten(arr) {
// TODO
let res=[];
arr.forEach(el=>{
if(Array.isArray(el)){
res=res.concat(flatten(el));
}else{
res.push(el);
}
})
return res;
} 4.假设客户最后的权重为c,则a(j-1)+b(n-j)=c 可以推出(a-b)j+(-a+bn)=c
其中(-a+bn)为定值,因此只要使(a-b)j越小,c就越小
由于j为下标,显然只要对数组的(a-b)结果降序就是所得序列,然后跑流程就行了
由于很多人问第四题的错误点,这里说几个有可能的
首先你的排序必须是高效的排序算法(不过应该没人手撕些奇怪的排序吧)
另外,如果你是c++选手,这题就有坑了,在数据可能超int,所以没开longlong的一律爆炸(估计)
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<queue>
#include<functional>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<stack>
using namespace std;
typedef long long LL;
const int maxn=int(1e5)+10;
const int inf=0x7f7f7f7f;
const LL INF=0x7f7f7f7f7f7f7f7f;
const int mod=int(1e9)+7;
struct nodes{
LL x,y;
nodes(LL _x=0,LL _y=0){
x=_x;
y=_y;
}
bool operator <(const nodes &a)const{
return (x-y)>(a.x-a.y);
}
}num[maxn];
int main(){
//freopen("D:\\code\\c++\\test\\in.txt","r",stdin);
LL n;
while(~scanf("%lld",&n)){
for(int i=0;i<n;i++){
scanf("%lld%lld",&num[i].x,&num[i].y);
}
sort(num,num+n);
// for(int i=0;i<n;i++){
// printf("%lld %lld\n",num[i].x,num[i].y);
// }
LL res=0;
for(LL i=0;i<n;i++){
res=res+i*num[i].x+(n-i-1)*num[i].y;
}
printf("%lld\n",res);
}
}
5.不会(我连题都没读懂,太菜了)
求大佬讲一下第五题是啥东西
#腾讯##笔试题目##前端工程师#
查看3道真题和解析
老板电器公司氛围 197人发布