腾讯2019实习生笔试(编程题)

题目还没放出来,等更新。堆头文件习惯,别见怪。

A题:找规律

注意结果开long long

#include <fstream>
#include <iostream>    
#include <stdio.h>    
#include <string.h>    
#include <stack>    
#include <queue>    
#include <map>    
#include <set>    
#include <vector>    
#include <math.h>    
#include <bitset>    
#include <algorithm>    
#include <climits>   
#include<iomanip>
#include<math.h>
#include<utility>
long long ans = 0;

using namespace std;
int main() {
    long long n, m;
    while (cin>>n>>m)
    {
        ans = (n / 2)*m;
        cout << ans << endl;
    }
}

B题 卢卡斯定理

#include <fstream>
#include <iostream>    
#include <stdio.h>    
#include <string.h>    
#include <stack>    
#include <queue>    
#include <map>    
#include <set>    
#include <vector>    
#include <math.h>    
#include <bitset>    
#include <algorithm>    
#include <climits>   
#include<iomanip>
#include<math.h>
#include<utility>
typedef long long LL;

LL n, m, p=1000000007;

LL QM(LL num1, LL num2)
{
    LL ans = 1;
    num1 %= p;
    while (num2)
    {
        if (num2 & 1)
        {
            ans = ans * num1 % p;
            num2--;
        }
        num2 >>= 1;
        num1 = num1 * num1 % p;
    }
    return ans;
}

LL C(LL n, LL m)
{
    if (m > n) return 0;
    LL ans = 1;
    for (int i = 1; i <= m; i++)
    {
        LL num1 = (n + i - m) % p;
        LL num2 = i % p;
        ans = ans * (num1 * QM(num2, p - 2) % p) % p;
    }
    return ans;
}

LL Lucas(LL n, LL m)
{
    if (m == 0) return 1;
    return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
LL anss;

using namespace std;
int main() {
    int k,a,x,b,y;
    while (cin>>k>>a>>x>>b>>y)
    {
        anss = 0;
        int tem_k = k;
        for (int i = 0; i <= x; i++) {
            tem_k = (k - i*a);
            if (tem_k<0)
            {
                break;
            }
            int tem_x = i;
            if (((tem_k%b) == 0)&&((tem_k/b)<=y)) {
                int tem_y = tem_k / b;
                if (i == 0) {
                    anss = (anss+ Lucas(y, tem_y)) % p;
                }
                else
                {
                    anss = (anss + Lucas(x, tem_x)*Lucas(y, tem_y)) % p;
                }
            }
        }
        cout << anss << endl;
    }
}

C题 贪心

(代码来自另一个大牛)感觉可能是后台数据不严谨,最后卡过去了,因为影响系数还有等级。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int SIZE = 1e5 + 5;

struct Base
{
    int time;
    int level;
};

Base machine[SIZE];
Base task[SIZE];
int record[105];    // 记录每个机器level数

bool cmp(const Base &a, const Base &b)
{
    if (a.time == b.time)
        return a.level > b.level;
    else
        return a.time > b.time;
}


int main(int argc, char const *argv[])
{
    int n, m, ansNum;
    long long ans;
    while (~scanf("%d %d", &n, &m))
    {
        ans = ansNum = 0;
        memset(machine, 0, sizeof(machine));
        memset(task, 0, sizeof(task));
        memset(record, 0, sizeof(record));

        for (int i = 0; i < n; ++i)
        {
            scanf("%d %d", &machine[i].time, &machine[i].level);
        }

        for (int i = 0; i < m; ++i)
        {
            scanf("%d %d", &task[i].time, &task[i].level);
        }

        sort(machine, machine + n, cmp);
        sort(task, task + m, cmp);

        int j = 0;
        for (int i = 0; i < m; ++i)
        {
            while (j < n && task[i].time <= machine[j].time)
            {
                ++record[machine[j].level];
                ++j;
            }

            for (int level = task[i].level; level < 101; ++level)
            {
                if (record[level])
                {
                    --record[level];
                    ++ansNum;
                    ans = ans + task[i].time * 200 + task[i].level * 3;
                    break;
                }
            }
        }
        printf("%d %lld\n", ansNum, ans);
    }
    return 0;
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值