2024.6.20 网易互娱笔试 (已 ak )
第一题:纯模拟题
#include<bits/stdc++.h> using namespace std; int n = 5; int a[6],b[6],aa[6],bb[6]; int main() { for(int i = 1;i<=5;i++)cin>>a[i]; for(int i = 1;i<=5;i++)cin>>aa[i]; for(int i = 1;i<=5;i++)cin>>b[i]; for(int i = 1;i<=5;i++)cin>>bb[i]; bool flag = true; int cnt1 = 1, cnt2 = 1; while(cnt1 <=5 && cnt2 <=5) { //轮到小易 if(flag) { bb[cnt2]-=a[cnt1]; flag = false; if(bb[cnt2]<=0)cnt2++; } else { aa[cnt1]-=b[cnt2]; flag = true; if(aa[cnt1]<=0)cnt1++; } } if(cnt1 <=5) { cout << "win"<<endl; cout << n - cnt1 + 1 <<endl; } else { cout << "lose"<<endl; cout << n - cnt2 + 1 <<endl; } }
第二题:递归求组合数 然后再进行计算最大值就好了
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 410; int n; struct jianzhu { int val; int a; int b; int c; }p[N]; int sum = 0; void dfs(int val, int aa,int bb,int cc,int start) { if(start>n) { return; } for(int i = start; i <=n;i++) { if(aa>=p[i].a && bb>=p[i].b && cc>=p[i].c) { sum = max(sum,val + p[i].val); dfs(val + p[i].val, aa - p[i].a,bb-p[i].b,cc-p[i].c,i + 1); } } } signed main() { int A,B,C; cin>>n>>A>>B>>C; for(int i = 1;i<=n;i++) { int a,b,c,v; cin>>a>>b>>c>>v; p[i]={v,a,b,c}; } dfs(0,A,B,C,1); cout << sum <<endl; return 0; }
第三题:先把坐标整体偏移2000,然后做一次二维差分数组就好了,一开始以为是哈希,推了半天没推了,后面发现,这不裸着的二维差分数组嘛!
#include<bits/stdc++.h> using namespace std; const int N = 100010; int n,q; int b[5000][5000]; struct Dian { int x,y,r; }dian[N]; void add(int x1,int y1,int x2,int y2,int c) { b[x1][y1]+=c; b[x1][y2+1]-=c; b[x2+1][y1]-=c; b[x2+1][y2+1]+=c; } signed main() { cin>>n; for(int i =1;i<=n;i++) { int x,y,r; cin>>x>>y>>r; x+=2000,y+=2000; dian[i] = {x,y,r}; add(x-r,y-r,x+r,y+r,1); } for(int i = 1;i<=5000;i++) { for(int j = 1;j<=5000;j++) { b[i][j] = b[i][j] + b[i-1][j] + b[i][j-1] - b[i-1][j-1]; } } cin>>q; while(q--) { int x0,y0; cin>>x0>>y0; x0+=2000,y0+=2000; cout <<b[x0][y0]<<endl; } return 0; }
今天的题目好简单阿,一小时ak,好久没那么爽了,感谢网易互娱~~
#网易互娱##网易互娱笔试#