1
2 头条笔试题
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main(){
int N;
cin>>N;
for(int n=0;n<N;++n){
int L, minVal, minPos;
minVal = 1000;
minPos = 0;
cin>>L;
vector<int> v(L, 0);
for(int l=0;l<L;l++){
cin>>v[l];
if(v[l]<minVal){
minVal = v[l];
minPos = l;
}
}
vector<int> reward(v.size(), 0);
reward[minPos] = 1;
for(int k=0;k<L;k++){
int pos = k+minPos;
if (pos>=L){
pos = pos - L;
}
if(pos==0){
if(v[pos]>v[L-1]) reward[pos] = reward[L-1]+1;
else if(v[pos]==v[L-1]) reward[pos] = reward[L-1] - 1;
else reward[pos]=reward[pos];
}
else{
if(v[pos]>v[pos-1]) reward[pos] = reward[pos-1]+1;
else if(v[pos]==v[pos-1]) reward[pos] = reward[pos-1] - 1;
else reward[pos]=reward[pos];
}
}
cout<<accumulate(reward.begin(),reward.end(),0)<<endl;
}
return 0;
}
3 头条笔试题
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
vector<int> zhaoqian(int N){
vector<int> v(4,0);
N = 1024 - N;
int value[4] = {64, 16, 4, 1};
for(int i=0;i<(sizeof(value)/sizeof(value[0]));i++){
cout<<i<<endl;
int a = N/value[i];
v[i] = a;
N = N%value[i];
}
return v;
}
int main(){
int N;
cin>>N;
vector<int> vv;
vv = zhaoqian(N);
cout<<accumulate(vv.begin(), vv.end(), 0)<<endl;
return 0;
}
4 招行笔试题
题目描述:切不等高的蛋糕,蛋糕N份,每刀切平一部分,切下来的不得超过k份,整块蛋糕切平最少需要几刀,比如如下输入
5 6
1 2 3 4 5
提示:第一刀可以切到2,切下来刚好是6份,剩下蛋糕为1 2 2 2 2
第二刀全切到1,最少需要2刀1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <stack>
#include <vector>
using namespace std;
int main(){
int N,k;
cin>>N>>k;
vector<int> v(N, 0);
for(int l=0;l<N;l++){
cin>>v[l];
}
sort(v.begin(),v.end());
int minVal = v.front();
int maxVal = v.back();
int dao = 0;
bool hello = false;
int i = 0;
while(i<v.size()){
if(hello) i=0;
if(minVal==maxVal) break;
int sum = 0;
bool flag = true;
int minVal1=v[i];
for(int j=v.size()-1;j>i;--j){
sum = sum+(v[j]-minVal1);
if(sum>k){
flag = false;
break;
}
}
if(flag){
dao++;
hello = true;
for(int g=v.size()-1;g>i;g--){
v[g] = v[g]-(v[g]-minVal1);
}
}
maxVal=v.back();
i++;
}
cout<<dao;
return 0;
}