当前位置: 首页 > 面试经验 >

鹰角网络游戏客户端端笔试题解 2023.3.22 附源码

优质
小牛编辑
94浏览
2023-03-28

鹰角网络游戏客户端端笔试题解 2023.3.22 附源码

T1 100/100

组合数学,先判断哪些小火龙可以打到怪物,然后用总方案减去每一条小火龙都没打到怪物的情况即可


typedef long long ll;
class Solution {
public:
int methodsOfKillingMonster(vector<vector<int> >& a, vector<int>& b) {
ll mod=1e9+7;
auto qpow=[&](ll x,ll y) {
ll ans=1;
while(y) {
if(y%2==1) ans=ans*x%mod;
x=x*x%mod;
y/=2;
}
return ans;
};
int cnt=0;
for(auto i:a) if(i[0]==b[0]||i[1]==b[1]) ++cnt;
ll ans=qpow(4,a.size());
ans=(ans-qpow(3,cnt)*qpow(4,a.size()-cnt)%mod+mod)%mod;
return ans;
}
};

T2 100/100

这题是真打表找规律


typedef long long ll;
class Solution {
public:
int countOfE(int n) {
ll mod=1e9+7;
auto qpow=[&](ll x,ll y) {
ll ans=1;
while(y) {
if(y%2==1) ans=ans*x%mod;
x=x*x%mod;
y/=2;
}
return ans;
};
ll ans=qpow(25,n-1)*n%mod;
return ans;
}
};

T3 44/100

没怎么理解构造方案,事后根别人讨论说也许可以先处理出左右子树的个数,再根据个数填入


/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* };
*/
class Solution {
public:
TreeNode* dfs(int l,int r) {
if(l>r) return nullptr;
int len=r-l+1;
TreeNode* now=new TreeNode(-1);
if(len%2==0) {
now->val=l+len/2;
}
else {
if(len==1) now->val=l;
else if(len==3) now->val=l+1;
else now->val=l+len/2+1;
}
now->left=dfs(l,now->val-1);
now->right=dfs(now->val+1,r);
return now;
}

TreeNode* maxDepthAVL(int n) {
return dfs(1,n);
}
};

T4 100/100

st表维护区间最小值+单调栈找下一个大于当前数字的数


typedef long long ll;
class Solution {
public:
vector<int> getEmotion(vector<int>& a) {
int n=a.size();
vector<vector<ll>> st(n,vector<ll>(32,0x3f3f3f3f));
for(int i=0;i<n;++i) st[i][0]=a[i];
for(int j=1;j<32;++j)
for(int i=0;i+(1ll<<j)-1<n;++i)
st[i][j]=min(st[i][j-1],st[i+(1ll<<(j-1))][j-1]);
auto lg=[&](int x) {
ll ans=0;
ll tmp=1;
while(tmp*2<x) {
tmp*=2;
++ans;
}
return ans;
};
auto mn=[&](int l,int r) {
int len=r-l+1;
int j=lg(len);
return min(st[l][j],st[r-(1ll<<j)+1][j]);
};
vector<int> flg(n);
stack<int> s;
for(int i=n-1;i>=0;--i) {
while(!s.empty()&&a[i]>=a[s.top()]) s.pop();
if(s.empty()) flg[i]=n-1;
else flg[i]=s.top();
s.push(i);
}
// for(int i=0;i<n;++i) cout<<flg[i]<<' ';cout<<endl;
vector<int> ans(n);
for(int i=0;i<n;++i) ans[i]=a[i]-mn(i,flg[i]);
return ans;
}
};

#笔试##鹰角网络#
 类似资料: