网易互娱9.27初级游戏研发工程师笔试题

好吧,总共三题,只会第一题。。。有没有大佬给个二三题啊
#include<iostream>
#include<vector>

using namespace std;

vector<int> numToVec( int num)
{
vector<int> vec;
while (num > 0)
{
vec.push_back(num % 10);
num = num / 10;
}
return vec;
}
int main()
{
int n;
cin >> n;
const int num = 10;
vector<int> res(num);
while (n-->0)
{
int a, b;
cin >> a >> b;

vector<int> arr(num);
int tmp = b;
bool isa = true;
bool isb = true;
bool isab = true;
while (tmp > 0)
{
int res = 0;
if (isa)
{
res = a;
isa = false;
}
else if (isb)
{
res = b;
isb = false;
}
else if (isab)
{
res = a * tmp;
isab = false;
}
else
{
res = a * (tmp % 10);
tmp = tmp / 10;
}

vector<int> vec=numToVec(res);
for (int i = 0; i < vec.size(); i++)
arr[vec[i]]++;

}
for (int i = 1; i < num; i++)
{
cout << arr[i] << " ";
res[i] += arr[i];
}
cout << endl;

}
int maxNum = res[1];
int luck = 1;
for (int i = 1; i < num; i++)
{
if (res[i] > maxNum)
{
maxNum = res[i];
luck = i;
}
}
cout << luck << endl;
//system("pause");
return 0;
}

#网易互娱##笔试题目##题解##游戏工程师#
全部评论
public class WY2 {     static int cost;     public static void main(String args[]) {         Scanner s = new Scanner(System.in);         int Numoftest = s.nextInt();         s.nextLine();         for(int outterCount=0; outterCount<Numoftest;outterCount++) {             String inputseq = s.nextLine();                          char[] position = new char[] {'A','S','D','F','G','H'};             cost = 0;             cost = getcost(inputseq,position);             allpailie(position,0,6,inputseq);             System.out.println(cost);         }     }          public static int getcost(String input, char[] position) {         int cost =0;         int lastposition=0;         for(int i=0;i<input.length();i++) {             char c = input.charAt(i);             for(int j=0;j<6;j++) {                 if(position[j] == c) {                                         cost = cost + Math.abs(j-lastposition);                     lastposition =j;                 }             }         }         return cost;     }          public static void allpailie(char[] position, int start,int end,String input) {         char temp;         if(start < end -1) {             allpailie(position, start+1, end,input);             for(int i= start+1;i<end;i++) {                 temp = position[start];                 position[start] = position[i];                 position[i] = temp;                 allpailie(position, start+1, end,input);                     temp = position[start];                 position[start] = position[i];                 position[i] = temp;             }                     }else {             int currentcost = getcost(input,position);             if(currentcost<cost) {                 cost=currentcost;             }         }     }      }
点赞 回复
分享
发布于 2019-09-27 21:30
暴力全排列。。。总共就6!= 720 种组合,数目不是很大,没超时。 /* FileName:  Author: Dev_Universe Date: 2019/9/27 19:34:00 Description: */ #include<bits/stdc++.h> using namespace std; vector<string> AllKeys; string temp = ""; char Keys[6] = {'A', 'S', 'D', 'F', 'G', 'H'}; void Perm(char *list, int low, int high) { if(high == low) { for(int i = 0; i <= low; i++) { temp += list[i]; } AllKeys.push_back(temp); temp = ""; } else { for(int i = low; i <= high; i++) { swap(list[i], list[low]); Perm(list, low + 1, high); swap(list[i], list[low]); } } } int Min_Cost(const string & str, string KeysOrder) { map<char, int> Letters; for(int i = 1; i < 7; i++) { Letters[KeysOrder[i-1]] = i; } int pos = 1; char let; int cost = 0; for(int i = 0; i < str.length(); i++) { let = str[i]; cost += abs(Letters[let] - pos); pos = Letters[let]; } return cost; } int main() { int T; cin>>T; map<char, int> Letters; Perm(Keys, 0, 5); while(T--) { string str; cin>>str; int min_cost = 70000; int cost  = 0; for(int i = 0; i < AllKeys.size(); i++) { cost = Min_Cost(str, AllKeys[i]); if(cost < min_cost) min_cost = cost; } cout<<min_cost<<endl; }     system("pause");//getchar(); return 0; }
点赞 回复
分享
发布于 2019-09-27 21:42
英特尔
校招火热招聘中
官网直投
感觉他们的数据量应该特别的小......我最后一题直接暴力模拟竟然过了(N多重嵌套循环)... 2的 package WY; import java.util.HashMap; import java.util.Map; import java.util.Scanner; /**  * 思路:  *      1. 暴力生成6个字母的全部排列试一下?  */ public class wangyi02 {     public static void main(String[] args){         wangyi02 wangyi02 = new wangyi02();         wangyi02.Input();     }     int T;     String str;     String[] array = {             "A","S","D","F","G","H"     };     String[] finalResult = new String[6];     // 用于表示某个字母目前在哪个位置     Map<String,Integer> finalMapping = new HashMap<>();     boolean[] visited = new boolean[6];     // 最小代价     int minReuslt = Integer.MAX_VALUE;     public void Input(){         Scanner in = new Scanner(System.in);         T = in.nextInt();         for(int i=0;i<T;i++){             str = in.next();             minReuslt = Integer.MAX_VALUE;             DFS(0);             System.out.println(minReuslt);         }     }     public void DFS(int index){         if(index==6){             // finalResult是最终生成的排列             Compute();             return;         }         for(int i=0;i<array.length;i++){             if(!visited[i]){                 visited[i] = true;                 finalResult[index] = array[i];                 finalMapping.put(array[i],index);                 DFS(index+1);                 visited[i] = false;             }         }     }     public void Compute(){         // 记录当前手放在哪个位置上         int nowIndex = 0;         // 代价         int result = 0;         for(int i=0;i<str.length();i++){             String ch = str.charAt(i)+"";             result += Math.abs(nowIndex - finalMapping.get(ch));             nowIndex = finalMapping.get(ch);         }         if(result<minReuslt){             minReuslt = result;         }     } } 3的 package WY; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; /**  * 思路:  *      1. 对着题意模拟.  * 坑:  *      1. 数量最多指的不是在整个游戏里数量最多,是指联通数量最多.  *      举例:  *          131  *          331  *      这里3的联通数量最多,因为1的联通数量最大是2,3是3  */ public class wangyi03 {     public static void main(String[] args){         wangyi03 wangyi03 = new wangyi03();         wangyi03.Input();     }     int T;     int M,N;     char[][] array;     // 当前要消除的方块的具***置     int nowRemoveI,nowRemoveJ;     public void Input(){         Scanner in = new Scanner(System.in);         T = in.nextInt();         for(int i=0;i<T;i++){             M = in.nextInt();             N = in.nextInt();             array = new char[M][N];             for(int j=0;j<M;j++){                 array[j] = in.next().toCharArray();             }             // 重置所有状态后进行计算             nowRemoveI = 0;             nowRemoveJ = 0;             DFScount = 0;             Slove();         }     }     public void Slove(){         while (nowRemoveI!=-1 && nowRemoveJ!=-1) {             // 第一步,找到要进行消除的方块             // 规则:             //   1. 数量最多; 2. 编号最小; 3. 行最小,列最小;             GetRemoveIndex();             if(nowRemoveI==-1 && nowRemoveJ==-1) break;             // 第二步,消除目标方块,并且应用规则重排整个数组(所有已空位置设为'#')             Remove();             // 每完成一步输出一下 //            Print(); //            System.out.println();         }         int c = 0;         // 第三步,找到剩余格子数量并输出         for(int i=0;i<M;i++)             for(int j=0;j<N;j++)                 if(array[i][j]!='#') c++;         System.out.println(c);     }     int DFScount = 0;     int[][] dir = new int[][]{             {1,0},   // 下             {0,1},  // 右             {-1,0}, // 上             {0,-1} // 左     };     public void DFS(int x,int y,char target,boolean[][] visited){         // 不搜空的地方         if(target=='#') return;         for(int i=0;i<4;i++){             int tempX = x+dir[i][0];             int tempY = y+dir[i][1];             if(tempX>=0&&tempX<M&&tempY>=0&&tempY<N && !visited[tempX][tempY] && array[tempX][tempY]==target){                 visited[tempX][tempY] = true;                 DFScount ++;                 DFS(tempX,tempY,target,visited);             }         }     }     // DFS找到联通数量最多的方块     public void FindMaxCount(int[] count){         boolean[][] visited = new boolean[M][N];         for(int i=0;i<M;i++){             for(int j=0;j<N;j++){                 if(!visited[i][j] && array[i][j]!='#'){                     DFScount = 1;                     visited[i][j] = true;                     DFS(i,j,array[i][j],visited);                     if(DFScount>count[array[i][j]-'0']){                         count[array[i][j]-'0'] = DFScount;                     }                 }             }         }     }     public void GetRemoveIndex(){         // 首先找数量最多的         int maxCount = 0;         // count[i]表示第i个数字的最大联通数量         int[] count = new int[10];         FindMaxCount(count);         for(int i=0;i<10;i++) maxCount = Math.max(maxCount,count[i]);         if(maxCount == 1 || maxCount==0){             // 最大数量为1的时候,说明已经没有方块可以消除了             nowRemoveI = -1;             nowRemoveJ = -1;             return;         }         char minIndex = 0;         // 找到数量最多之中的编号最小的         for(int i=0;i<10;i++){             if(count[i]==maxCount){                 minIndex = (char)(i+'0');                 break;             }         }         boolean[][] visited = new boolean[M][N];         // 找到编号最小的之中行最小,列最小的(还得是数量最多的)         for(int i=0;i<M;i++){             for(int j=0;j<N;j++){                 if(array[i][j]==minIndex && !visited[i][j]) {                     visited[i][j] = true;                     DFScount = 1;                     DFS(i, j,minIndex,visited);                     if(DFScount == maxCount){                         nowRemoveI = i;                         nowRemoveJ = j;                         return;                     }                 }             }         }     }     public void DFSRemove(int x,int y,char target,boolean[][] visited){         // 不搜空的地方         if(target=='#') return;         array[x][y] = '#';         for(int i=0;i<4;i++){             int tempX = x+dir[i][0];             int tempY = y+dir[i][1];             if(tempX>=0&&tempX<M&&tempY>=0&&tempY<N && !visited[tempX][tempY] && array[tempX][tempY]==target){                 visited[tempX][tempY] = true;                 DFSRemove(tempX,tempY,target,visited);             }         }     }     public void Remove(){         boolean[][] visited = new boolean[M][N];         DFSRemove(nowRemoveI,nowRemoveJ,array[nowRemoveI][nowRemoveJ],visited);         // 重排数组,只要一列中#上方的不是#,那么就继续重排         for(int j=0;j<N;j++){             while (true) {                 boolean isBreak = true;                 for (int i = 0; i < M; i++) {                     // 如果下面的格子为空,那么将它与它下面的格子交换                     int bottom = i+1;                     if(bottom<M && array[bottom][j]=='#'){                         array[bottom][j] = array[i][j];                         array[i][j] = '#';                     }                 }                 for(int i=0;i<M;i++){                     // 只要#上方不是#,就继续重排                     int top = i-1;                     if(top>=0 && array[i][j]=='#' && array[top][j]!='#') {                         isBreak = false;                         break;                     }                 }                 if(isBreak) break;             }         } //        for(int i=0;i<M;i++){ //            for(int j=0;j<N;j++){ //                // 如果下面的格子为空,那么将它与它下面的格子交换 //                int bottom = i+1; //                if(bottom<M && array[bottom][j]=='#'){ //                    array[bottom][j] = array[i][j]; //                    array[i][j] = '#'; //                } //            } //        }         // 第一列为空的情况下,不停的运行这段代码         while (true) {             // 第一列空格子数量             int oneColEmpty = 0;             // 是否整个数组都为空             boolean isEmpty = true;             // 如果某一列为空,那么将其右边的一列来取代他             for (int j = 0; j < N; j++) {                 // 该列空格子数                 int colEmpty = 0;                 for (int i = M - 1; i >= 0; i--) {                     if (array[i][j] == '#') colEmpty++;                     if(array[i][j]=='#' && j==0) oneColEmpty++;                 }                 int right = j + 1;                 // 空格子数==M表示该列为空,那么让其右边的一列取代他                 if (colEmpty == M && right < N) {                     for (int i = 0; i < M; i++) {                         array[i][j] = array[i][right];                         array[i][right] = '#';                     }                 }                 if(colEmpty!=M) isEmpty = false;             }             if(oneColEmpty!=M) break;             // 整个数组为空的情况下也结束循环             if(isEmpty) break;         }     }     public void Print(){         for(int i=0;i<M;i++){             for(int j=0;j<N;j++){                 System.out.print(array[i][j]);             }             System.out.println();         }     } } 代码写的比较烂....因为时间比较赶...献丑了5555
点赞 回复
分享
发布于 2019-09-27 22:58
第一题感觉也不用这么麻烦,有小技巧~~~....对于123*456,实际上只要数6*123,5*123,4*123,三个结果里面每个字符的数量就好了(再加上ab本身和a*b本身). package WY; import java.util.Scanner; /**  * 思路:  *      1. 对两个数字逐位计算,假设要计算 a*b,  *      则列式为:  *          a[0] a[1] a[2] .. a[N]  *        x b[0] b[1] b[2] .. b[N]  *  *      结果第一行是b[N]*a[N] , a[N-1] ... a[1],  *  *      模拟即可,需要考虑进位.  *  *  */ public class wangyi01 {     public static void main(String[] args){         wangyi01 wangyi01 = new wangyi01();         wangyi01.Input();     }     int N;     // 记录每位的数字出现次数     int[] count = new int[10];     public void Input(){         Scanner in = new Scanner(System.in);         N = in.nextInt();         for(int i=0;i<N;i++){             int a = in.nextInt();             int b = in.nextInt();             Slove(a,b);         }         int max = 0;         int maxNumber = 0;         for(int i=1;i<=9;i++){             if(count[i]>max){                 max = count[i];                 maxNumber = i;             }         }         System.out.println(maxNumber);     }     public void Slove(int a,int b){         int[] tempCount = new int[10];         String strb = String.valueOf(b);         for(int i=0;i<strb.length();i++){             int num = strb.charAt(i)-'0';             int result = num * a;             String strResult = String.valueOf(result);             for(int j=0;j<strResult.length();j++){                 int number = strResult.charAt(j)-'0';                 count[number]++;                 tempCount[number]++;             }         }         // 计算a*b         String strResult = String.valueOf(a*b);         for(int j=0;j<strResult.length();j++){             int number = strResult.charAt(j)-'0';             count[number]++;             tempCount[number]++;         }         // 计算a         strResult = String.valueOf(a);         for(int j=0;j<strResult.length();j++){             int number = strResult.charAt(j)-'0';             count[number]++;             tempCount[number]++;         }         // 计算b         strResult = String.valueOf(b);         for(int j=0;j<strResult.length();j++){             int number = strResult.charAt(j)-'0';             count[number]++;             tempCount[number]++;         }         System.out.print(tempCount[1]);         for(int i=2;i<=9;i++){             System.out.print(" "+tempCount[i]);         }         System.out.println();     } }
点赞 回复
分享
发布于 2019-09-27 23:08
请问题目是什么呀😥
点赞 回复
分享
发布于 2020-09-04 12:20

相关推荐

点赞 6 评论
分享
牛客网
牛客企业服务