网易互娱游戏研发实习生笔试题代码分享
// test1 [100/100]
平铺后 串一下位置就行啦
#include <bits/stdc++.h>using namespace std; char s[333][333]; char ans[444][444]; int main(){ int _,n,m; for(scanf("%d",&_);_--;){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++){ scanf("%s",s[i]); } for(int i=0;i<m+m;i++){ for(int j=0;j<m+m;j++){ ans[i][j] = s[i%n][j%n]; } ans[i][m+m]='\0'; // puts(ans[i]); } //puts(" -- "); int k; for(int i=1;;i+=2){ if(n*i >= m){ k = (n*i)-m; k/=2; break; } } for(int i=0;i<m;i++){ ans[i+k][m+k] = '\0'; puts(ans[i+k]+k); } puts(""); //puts(" ----- "); } return 0; }
// test2 [100/100]
二分答案就好了
注意如果又能打前锋和中场单独记下来 然后补位就行啦
#include <bits/stdc++.h>using namespace std; int n,x,y; vector<pair<int,int> >xy; bool check(int mid){ int a = 0,b = 0,c = 0; for(auto yx: xy){ if(yx.first>=mid && yx.second>=mid) c++; else if(yx.first>=mid)a++; else if(yx.second>=mid)b++; } bool flag = false; if(a>=x&&b>=y) flag = true; else if(min(x,a)+min(y,b)+c >= x+y) flag = true; return flag; } int main(){ int _ ; for(scanf("%d",&_);_--;){ scanf("%d%d%d",&n,&x,&y); xy.clear(); for(int i=1,a,b;i<=n;i++){ scanf("%d%d",&a,&b); xy.push_back({a,b}); } int l = 0,r = 10000,ans = 0,mid; while(l<=r){ mid = l+r>>1; if(check(mid)) ans = mid,l = mid+1; else r = mid -1; } printf("%d\n",ans); } return 0; }
// test3 [100/100]
全排列下暴力判就行了
用一个长度为28的二进制表示一个状态就行了
#include <bits/stdc++.h>
using namespace std;
char s[3][3];
int a[10];
set<int>ss;
int solve(int x,int y){
if(x>y) swap(x,y);
if(x == 0){
if(y == 1){return (1<<0);}
else if(y == 2){return (1<<0)+(1<<1);}
else if(y == 3){return (1<<2) ;}
else if(y == 4){return (1<<3) ;}
else if(y == 5){return (1<<20) ;}
else if(y == 6){return (1<<2)+(1<<11) ;}
else if(y == 7){return (1<<24) ;}
else if(y == 8){return (1<<3)+(1<<15) ;}
}
else if(x == 1){
if(y == 2){return (1<<1) ;}
else if(y == 3){return (1<<4) ;}
else if(y == 4){return (1<<5) ;}
else if(y == 5){return (1<<6) ;}
else if(y == 6){return (1<<21) ;}
else if(y == 7){return (1<<5)+(1<<14) ;}
else if(y == 8){return (1<<22) ;}
}
else if(x == 2){
if(y == 3){return (1<<23) ;}
else if(y == 4){return (1<<7) ;}
else if(y == 5){return (1<<8) ;}
else if(y == 6){return (1<<7)+(1<<13) ;}
else if(y == 7){return (1<<25) ;}
else if(y == 8){return (1<<8)+(1<<17) ;}
}
else if(x == 3){
if(y == 4){return (1<<9) ;}
else if(y == 5){return (1<<9)+(1<<10);}
else if(y == 6){return (1<<11) ;}
else if(y == 7){return (1<<12) ;}
else if(y == 8){return (1<<26) ;}
}
else if(x == 4){
if(y == 5){return (1<<10) ;}
else if(y == 6){return (1<<13) ;}
else if(y == 7){return (1<<14) ;}
else if(y == 8){return (1<<15) ;}
}
else if(x == 5){
if(y == 6){return (1<<27) ;}
else if(y == 7){return (1<<16) ;}
else if(y == 8){return (1<<17) ;}
}
else if(x == 6){
if(y == 7){return (1<<18) ;}
else if(y == 8){return (1<<18)+(1<<19) ;}
}
else if(x == 7){
if(y == 8){return (1<<19) ;}
}
return 0;
}
int main(){
int _ ;
for(scanf("%d",&_);_--;){
int len = 0;
ss.clear();
for(int i=0;i<3;i++){
scanf("%s",s[i]);
for(int j=0;j<3;j++){
if(s[i][j] == '.')
a[len++]=i*3+j;
}
}
int tmp = 0;
//printf("len = %d\n",len);
do{
tmp = 0;
for(int i=len-1;i>0;i--){
tmp |= solve(a[i],a[i-1]);
ss.insert(tmp);
}
}while(next_permutation(a,a+len));
printf("%d\n",ss.size());
}
return 0;
}
查看25道真题和解析