9.28 剑心互娱笔试

1、模拟小飞机游戏; 100%;
#include <iostream>
#include <vector>

using namespace std;


long ret = 0;
long path = 1;
void get_dis(vector<string>& num_map, vector<vector<bool>>& vis, int x, int y){
    if( !(x>=0&& x< num_map.size() && y>=0 && y< 8) || num_map[x][y] == '1' || vis[x][y]){
        return;
    }
    ret = max(path, ret);
    vis[x][y] = true;
    
    get_dis(num_map, vis, x, y+1);
    get_dis(num_map, vis, x, y-1);
    path += 1;
    get_dis(num_map, vis, x+1, y);
    path -= 1;
}


int GetFarthestRoad(vector<uint8_t>& vecRoad)
{
      // todo 
    vector<string> num_map;
    for(int i=0; i< vecRoad.size(); i++){
        string map_i(8, '0');
        uint8_t num = vecRoad[i];
        int idx = 0;
        while(num){
            if(num % 2){
                map_i[idx] = '1';
            }
            idx++;
            num >>= 1;
        }
        num_map.push_back(map_i);
    }
    
    bool fig = false;
    for(int i=0; i< 8; i++){
        if(num_map[0][i] == '0'){
            if(!fig)
                ret = 1;
            fig = true;
            vector<vector<bool>> vis(num_map.size(), vector<bool>(8, false));
            get_dis(num_map, vis, 0, i);
        }
    }
    return ret;
}


int main() {
	vector<uint8_t> vecRoad;
	int tmp;
	while (cin >> tmp)
		vecRoad.push_back((uint8_t)tmp);
    
    cout<<GetFarthestRoad(vecRoad);
    return 0;
}


2、进水出水问题; 100%;
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param m int整型 水池容量
     * @param t int整型 总时长
     * @param m1 int整型 进水阀打开时每分钟进水量
     * @param t1 int整型 进水阀开关切换时长
     * @param m2 int整型 排水阀打开时每分钟排水量
     * @param t2 int整型 排水阀开关切换时长
     * @return int整型
     */
    int ComputeRemanentWater(int m, int t, int m1, int t1, int m2, int t2) {
        // write code here
        
        int time = 0;
        bool in_fig = true, out_fig = true;
        int cap = 0;
        while(time< t){
            if(in_fig && out_fig){
                cap = cap + (m1-m2);
                cap = min(cap, m);
                cap = max(0, cap);
            }
            else if(in_fig){
                cap = min(cap+m1, m);
            }
            else if(out_fig){
                cap = max(0, cap-m2);
            }
            
            time += 1;
            if(time % t1 == 0){
                in_fig = in_fig? false: true; 
            }
            if(time % t2 == 0){
                out_fig = out_fig? false: true;
            }
        }
        return cap;
    }
};
3、给定三角形得三个点,判断三角形覆盖得正方形个数; 思路:模拟,不想做
4、有4种购买策略,分别对应于不同的格子,每个格子可以放比他小的商品,现给一堆商品,给出最小的花费;思路:暴力回溯,不想做

#剑心互娱#
全部评论
今天答那个进出水问题,time++已经不行了,太慢,只能过20%了
4
送花
回复
分享
发布于 2022-10-18 15:33 陕西
好兄弟另外两道还记得是什么吗
点赞
送花
回复
分享
发布于 2022-09-28 21:05 陕西
滴滴
校招火热招聘中
官网直投
离谱…题都不变的
点赞
送花
回复
分享
发布于 2022-10-11 17:20 四川
我今天也做到这题了,跟你一样显示的超时。是不是要求个最大公因数呢
点赞
送花
回复
分享
发布于 2022-10-30 20:47 四川

相关推荐

华为 鸿蒙客户端开发工程师 工作强度比较大,1,2,4要到10点半
点赞 评论 收藏
转发
头像
不愿透露姓名的神秘牛友
04-20 16:07
已编辑
冰川网络 c++开发 12k以下
点赞 评论 收藏
转发
15 54 评论
分享
牛客网
牛客企业服务