记录8.10大疆研发类笔试3AC代码

第一题
喝咖啡
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int N,A,X;
    while(cin>>N>>A>>X)
    {
        vector<int> times;
        times.resize(N);
        int sum = 0;
        for(int i = 0;i<N;i++)
        {
            cin>>times[i];
            sum = sum+times[i];
        }
        if(X > 8)
        {
            X = 8;
        }
        int speed_up_times = 60*A*X;
        int no_speed_times = (8-X)*60;
        if(speed_up_times + no_speed_times < sum)
        {
            cout<<0<<endl;
        }
        else
        {
            if(sum >= speed_up_times)
            {
                int left = sum-speed_up_times;
                cout<<X*60+left<<endl;
            }
            else
            {
                int hours = sum/(60*A);
                int left = sum-hours*60*A;
                int minute = left/A;
                if(left%A != 0)
                {
                    minute++;
                }
                cout<<hours*60+minute<<endl;
            }
        }
    }
}

第二题
挑零食
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int N,T;
    while(cin>>N>>T)
    {
        vector<int> prices;
        vector<int> happys;
        for(int i = 0;i<N;i++)
        {
            int price;
            int happy;
            cin>>price>>happy;
            int count;
            cin>>count;
            while(count--)
            {
                prices.push_back(price);
                happys.push_back(happy);
            }
        }
        vector<int> dp;
        dp.resize(T+1,0);
        int result = 0;
        for(int i = 0;i<prices.size();i++)
        {
            for(int j = T;j>=0;j--)
            {
                if(j-prices[i] == 0)
                {
                    dp[j] = max(dp[j],happys[i]);
                }
                else if(j-prices[i] > 0 && dp[j-prices[i]] != 0)
                {
                    dp[j] = max(dp[j-prices[i]]+happys[i],dp[j]);
                }
                if(dp[j] > result)
                {
                    result = dp[j];
                }
            }
        }
        cout<<result<<endl;
    }
}



第三题
搜索字符串
#include<iostream>
#include<vector>
#include<set>
using namespace std;
bool search(vector<vector<char>> &matrix,int i,int j,string &str,int index)
{
    if(i<0 || j<0 || i>=matrix.size() || j>= matrix[i].size())
    {
        return false;
    }
    else
    {
        if(matrix[i][j] == '#')
        {
            return false;
        }
        else
        {
            if(index == str.length()-1 && matrix[i][j] == str[index])
            {
                return true;
            }
            if(matrix[i][j] != str[index])
            {
                return false;
            }
            else
            {
                char temp = matrix[i][j];
                matrix[i][j] = '#';
                bool result = search(matrix,i+1,j,str,index+1) || search(matrix,i,j+1,str,index+1) || search(matrix,i-1,j,str,index+1) || search(matrix,i,j-1,str,index+1);
                matrix[i][j] = temp;
                return result;
            }
        }
    }
}
int main()
{
    int N;
    while(cin>>N)
    {
        vector<vector<char>> matrix;
        matrix.resize(N);
        set<string> Mset;
        for(int i = 0;i<N;i++)
        {
            string temp;
            cin>>temp;
            for(auto &j:temp)
            {
                matrix[i].push_back(j);
            }
        }
        int M;
        cin>>M;
        while(M--)
        {
            string str;
            cin>>str;
             for(int i = 0;i<matrix.size();i++)
            {
                for(int j = 0;j<matrix.size();j++)
                {
                    if(search(matrix,i,j,str,0))
                    {
                        Mset.insert(str);
                        goto next;
                    }
                }
            }
next:
            continue;
        }
        for(auto &i:Mset)
        {
            cout<<i<<endl;
        }
    }
}


#笔试题目##大疆#
全部评论
老哥稳,想问问之前阿里那个还有后续不
点赞 回复 分享
发布于 2020-08-11 11:26
老哥,题目能私信我一下吗?感谢
点赞 回复 分享
发布于 2020-08-13 11:45

相关推荐

11-28 17:58
门头沟学院 Java
美团 JAVA开发 n×15.5
牛客786276759号:百度现在晋升很难的 而且云这块的业务没美团好 你看百度股价都跌成啥样了
点赞 评论 收藏
分享
dongsheng66:如果想进大厂的话,在校经历没必要占这么大篇幅,可以把专业技能单独放一个专栏写,可以加个项目经历
点赞 评论 收藏
分享
评论
8
16
分享
牛客网
牛客企业服务