8.22腾讯笔试-技术研究和数据分析-第一次笔试

一共五道代码题,分别为《开锁》《勇闯币圈》《迎宾车队》《水站的水流量》前四道全a,cpp代码如下,第五题实在写不出来只能a10%,求指导
第一题
//开锁
/*input
1 2
1 100
2 4
347 177 40 84
107 282 347 193
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline ll read() {
    char c = getchar(); ll x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
std::vector<int> v[maxn];;
int main(){
    int n=read(), m=read();
    double ans=0.0;
    for(int j=0;j<n;j++){
        for(int t,i=0;i<m;i++){
            t=read();
            v[i].push_back(t);
        }
    }
    for(int i=0;i<m;i++){
        sort(v[i].begin(),v[i].end());
        for(int j=1;j<v[i].size();j++){
            v[i][j]+=v[i][j-1];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=1;j<=n;j++){
            ans+=1.0/(j)*v[i][j-1];
        }
    }
    printf("%.8f ",ans);


    return 0;
}

第二题
//勇闯币圈
/*input
3
0
0 0 1
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
2
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
10
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline ll read() {
    char c = getchar(); ll x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
double sta[3][3];
int main(){
    int T=read();
    while(T--){
        int t=read();
        double cur0, cur1, cur2, l0, l1, l2;
        cin>>l0>>l1>>l2;//稳定、跌、涨
        cur0=l0, cur1=l1, cur2=l2;

        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                cin>>sta[j][i];

        for(int i=0;i<t;i++){
            cur0=l0*sta[0][0]+l1*sta[1][0]+l2*sta[2][0];
            cur1=l0*sta[0][1]+l1*sta[1][1]+l2*sta[2][1];
            cur2=l0*sta[0][2]+l1*sta[1][2]+l2*sta[2][2];
            l0=cur0, l1=cur1, l2=cur2;
        }
        if(cur2>0.5) puts("1");
        else puts("0");
    }
    return 0;
}

第三题
//迎宾车队
/*input
7
1 2 3 44 45 46 47
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline ll read() {
    char c = getchar(); ll x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
int a[maxn];
int main(){
    int n=read();
    for(int i=0;i<n;i++){
        a[i]=read();
    }
    sort(a,a+n);
    int ans=0;
    int idx=0;
    for(int i=0;i<n;i++){
        while(a[idx]-a[i]<=10&&idx<n) idx++;
        ans=max(ans,idx-i);
    }
    cout<<ans<<endl;
    return 0;
}

第四题
//水站的水流量
/*input
3 1000
3 5
2 2
3 4
*/ 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline ll read() {
    char c = getchar(); ll x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
std::vector<int> G[maxn];
int a[maxn];
void dfs(int u, int fa, int cur){
    //cout<<u<<' '<<fa<<' '<<cur<<endl;
    if(cur<=0) return;
    if(G[u].size()==0) {
        a[u]+=cur;
        return;
    }
    if(a[u]<1024){
        if(a[u]+cur>=1024){
            cur=cur-(1024-a[u]);
            a[u]=1024;
            for(auto v:G[u]) dfs(v,u,cur/2);
        }
        else a[u]+=cur;
    }
    else{
        for(auto v:G[u]) dfs(v,u,cur/2);

    }
}
int main(){
    int n=read(), t=read();
    for(int i=0;i<n-1;i++){
        for(int u=1+i*(1+i)/2;u<=1+i*(1+i)/2+i;u++){
            int v1=u+i+1;
            int v2=u+i+2;
            G[u].push_back(v1);
            G[u].push_back(v2);
            //cout<<u<<' '<<v1<<' '<<v2<<endl;
        }
    }
    while(t--){
        dfs(1,0,1024);
    }
    int num=0;
    for(int i=1;i<maxn;i++){
        if(a[i]>=1024) num++;//, cout<<i<<endl;
    }
    cout<<num<<endl;
    return 0;
}
#腾讯笔试##腾讯##笔经#
全部评论
大佬能帮看下第一题吗?不知道卡哪了只过了60...感谢 int main() {   int m, n;   cin >> m >> n;   vector<vector<int>> a(m, vector<int>(n));   for(int i = 0;i < m;i++)     for(int j = 0;j < n;j++)       cin >> a[i][j];     double ans = 0;   for(int j = 0;j < n;j++){     priority_queue<int, vector<int>, greater<int>> q;     for(int i = 0;i < m;i++)       q.push(a[i][j]);     double sum = 0;     while(!q.empty()){       sum += q.top();       q.pop();       ans += sum/m;     }   }   cout << ans << endl;   return 0; }
点赞 回复 分享
发布于 2021-08-22 22:32
第 5 题可以看 leetcode 130
点赞 回复 分享
发布于 2021-08-22 22:11

相关推荐

2025-12-24 15:25
已编辑
门头沟学院 前端工程师
是腾讯的csig腾讯云,前天晚上九点突然打电话约面,激动的通宵学了一晚上,第二天状态很差改了今天(以后再也不通宵学习了)感觉自己浪费了面试官一个半小时单纯手写+场景,无八股无项目无算法,打击真的很大,全是在面试官提醒的情况下完成的,自己技术方面真的还是有待提高,实力匹配不上大厂和已经面试的两个公司完全不一样,很注重编码能力和解决问题的能力,然而我这两个方面都很薄弱,面试官人很好很耐心的等我写完题目,遇到瓶颈也会提醒我,写不出题也会很耐心的跟我讲解好感动,到最后面试结束还安慰我打算把下周最后一场面试面完之后就不面啦,如果能去实习还是很开心,但是最重要的还是好好努力提高技术以下是面经第一题//&nbsp;实现一个解析&nbsp;url&nbsp;参数的函数function&nbsp;parseUrl(urlStr)&nbsp;{//&nbsp;TODO}parseUrl('*********************************************');//&nbsp;返回&nbsp;{a:&nbsp;1,&nbsp;b:&nbsp;2,&nbsp;c:&nbsp;3}追问:在链接里见过什么部分?用&nbsp;hash&nbsp;路由的话放在哪第二题//&nbsp;考虑有一个异步任务要执行,返回&nbsp;Promise,这个任务可能会失败,请实现&nbsp;retry&nbsp;方法,返回新方法,可以在失败后自动重试指定的次数。/***&nbsp;异步任务重试*&nbsp;@param&nbsp;task&nbsp;要执行的异步任务*&nbsp;@param&nbsp;times&nbsp;需要重试的次数,默认为&nbsp;3&nbsp;次*/function&nbsp;retry(task,&nbsp;times&nbsp;=&nbsp;3)&nbsp;{//&nbsp;TODO:&nbsp;请实现}//&nbsp;---------------测试示例&nbsp;----------------//&nbsp;原方法const&nbsp;request&nbsp;=&nbsp;async&nbsp;(data)&nbsp;=&gt;&nbsp;{//&nbsp;模拟失败if&nbsp;(Math.random()&nbsp;&lt;&nbsp;0.7)&nbsp;{throw&nbsp;new&nbsp;Error('request&nbsp;failed');}const&nbsp;res&nbsp;=&nbsp;await&nbsp;fetch(&#39;https://jsonplaceholder.typicode.com/posts&#39;,&nbsp;{method:&nbsp;'POST',body:&nbsp;JSON.stringify(data),});return&nbsp;res.json();}//&nbsp;新的方法const&nbsp;requestWithRetry&nbsp;=&nbsp;retry(request);//&nbsp;使用async&nbsp;function&nbsp;run()&nbsp;{const&nbsp;res&nbsp;=&nbsp;await&nbsp;requestWithRetry({&nbsp;body:&nbsp;'content'&nbsp;});console.log(res);}run();第三题就是给&nbsp;retry&nbsp;函数添加类型注释,用到泛型第四题:在组件库中将&nbsp;Alert&nbsp;用&nbsp;api&nbsp;的形式实现(应该就是&nbsp;message&nbsp;这个组件)怎么渲染到一个浮层里而不是原地渲染出来
不知道怎么取名字_:技术这个东西,太杂了,而且要下功夫的
查看5道真题和解析
点赞 评论 收藏
分享
评论
点赞
14
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务