Written examination of 2019 Netease Internet school recruitment - programming questions
1. The old Tetris game machine.
Title: customize the number of Tetris columns. The number of Tetris dropped each time is 1 * 1. When a row is full of Tetris, score + 1. Now Xiaoming plays m Tetris and gets the score at this time.
Input:
Number of columns in the first row number of Tetris m
The second line a (1) a (2) a (3)... a(i)... A (m) indicates that the ith Tetris falls on line a(i)
Output: fractions
Example: input
3 9
1 1 2 2 2 3 1 2 3
Output: 2
Idea: count the number of repetitions c of each row in the array, and the score is c / number of columns n.
1 #include <iostream> 2 #include <string> 3 #include <stdio.h> 4 #include <algorithm> 5 using namespace std; 6 7 int main() 8 { 9 int a[2]; 10 for(int i=0;i<2;i++) cin>>a[i]; 11 char b[1000]; 12 for(int j=0;j<a[1];j++) 13 { 14 cin>>b[j]; 15 } 16 int c=0; 17 for(int i=0;i<sizeof(b);i++) 18 { 19 int n=b[0]; 20 for(int j=i+1;j<sizeof(b);j++) 21 { 22 if(n==b[j]) c+=1; 23 } 24 } 25 26 if(c<a[0]) cout<<0<<endl; 27 else cout<<c/a[0]<<endl; 28 //else cout<<1<<endl; 29 return 0; 30 31 }
2. There are always m minutes in a class. Xiao Ming is sleeping at some time, and the interest weight of each minute is different. Wake up Xiao Ming at the same table once, lasting n minutes. Now, given Xiaoming's interest weight in class every minute, and whether he is sleeping at the same time, ask Xiaoming to wake up at the same table once. What is Xiaoming's highest total efficiency in class after waking up (= interest weight per minute * interest weight per minute)?
Input:
Line 1: total time of a class m: wake up time
The second line a (1) a (2) a (3)... a(i)... A (m) a(i) represents the weight of interest in the first minute
In the third line, B (1) B (2) B (3)... B (i)... B (m) b(i)=0 or 1. In the first minute, if i was sleeping, 1 was awake, 0 was sleeping
Output: total listening efficiency
Example: input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output: 16
Train of thought: input m column, n minutes. The key is to find out the first few minutes to wake up Xiaoming. Find out the minimum value of N adjacent weights of interest per minute * waking state, that is, the time to wake up Xiaoming.
1 #include <iostream> 2 #include <string> 3 #include <stdio.h> 4 #include <algorithm> 5 using namespace std; 6 7 int main() 8 { 9 int a[2]; 10 for(int i=0;i<2;i++) cin>>a[i]; 11 int b[1000]; 12 for(int j=0;j<a[0];j++) cin>>b[j]; //Weight per minute 13 int c[1000]; 14 for(int j=0;j<a[0];j++) cin>>c[j]; //1 Sober up 15 int m[a[0]-a[1]+1]; //Used to store adjacent m Number b*c The minimum value of can be used to c=1 Of m Target number 16 for(int i=0;i<a[0]-a[1]+1;i++) 17 { 18 for(int j=1;j<a[1];j++) 19 { 20 m[i]=b[i]*c[i]; 21 m[i]+=b[j]*c[j]; 22 } 23 } 24 int number,max=0; 25 for(int i=0;i<(a[0]-a[1]+1);i++) 26 { 27 int min=m[0]; 28 if(min>m[i]) number=i; //The result should be in No number Minute make c=1 29 } 30 for(int j=0;j<number+a[1];j++) max+=b[j]; 31 cout<<max<<endl; 32 return 0; 33 }