定义S(n),表示n在十进制下的各位数字和。

现在给定一个x,请你求出最小正整数n,满足x<=S(n)。

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
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>

int main()
{
int num;
cin >> num;
vector<string> resV;
string a = "9";
for (int n = 0; n < num; n++)
{
int x;
cin >> x;
//long long int multi = 1;
string res;
while (x > 9)
{
x -= 9;
res = a + res;
//multi *= 10;
}
if (x != 0)
{
//res += multi * x;
res = to_string(x) + res;
}
resV.push_back(res);
}
for (int n = 0; n < num; n++)
{
cout << resV[n] << endl;
}
return 0;
}

小易给定你数字A, B (A < B)和系数p, q。每次操作你可以将A变成A + p或者将p变成p * q。问至少几次操作使得B <= A。

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
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>

int main()
{
int num;
cin >> num;
vector<long long int> resV;

for (int n = 0; n < num; n++)
{
long long int a;
long long int b;
long long int p;
long long int q;
cin >> a >> b >> p >> q;
long long int res = 0;
if (b - a > p)
{
long long int temp = b - a;
long long int multiNum = p;

while (temp > multiNum)
{
multiNum *= q;
res++;
}
res++;
}
else
{
res++;
}
resV.push_back(res);
}
for (int n = 0; n < num; n++)
{
cout << resV[n] << endl;
}
return 0;
}

小易定义一个数字序列是完美的,当且仅当对于任意2 <= i <= n,都满足img,即每个数字都要大于等于前面所有数字的和。
现在给定数字序列Ai,小易想请你从中找出最长的一段连续子序列,满足它是完美的。

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
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>


int main()
{
vector<int> resV;
int num;
cin >> num;
for (int i = 0; i < num; i++)
{
int tempLength = 1;
int maxLength = 0;
vector<int> n;
int serialNum;
cin >> serialNum;
for (int j = 0; j < serialNum; j++)
{
int data;
cin >> data;
n.push_back(data);
}
int compute = n[0];
for (int k = 1; k < serialNum; k++)
{
if (n[k] >= compute)
{
compute += n[k];
tempLength++;
}
else
{
maxLength = max(maxLength, tempLength);
tempLength = 1;
compute = n[k];
}
}
resV.push_back(maxLength);
}
for (int i = 0; i < num; i++)
{
cout << resV[i] << endl;
}
return 0;
}

小易的公司一共有n名员工, 第i个人每个月的薪酬是xi万元。
现在小易的老板向小易提了m次询问, 每次询问老板都会给出一个整数k, 小易要快速回答老板工资等于k的员工的数量。

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<algorithm>
#include<string>
#include<unordered_map>

using namespace std;
int main()
{

int people, question;
cin >> people >> question;
vector<int> resV(question, 0);
vector<int> salaryV;
vector<int> questionV;
unordered_map<string, size_t> questionMap;
for (int i = 0; i < people; i++)
{
int salary;
cin >> salary;
salaryV.push_back(salary);
}
for (int i = 0; i < question; i++)
{
int data;
cin >> data;
questionV.push_back(data);
questionMap[to_string(data)];
}
for (int i = 0; i < people; i++)
{
if (questionMap.find(to_string(salaryV[i])) != questionMap.end())
{
++questionMap[to_string(salaryV[i])];
}
}


for (int i = 0; i < question; i++)
{
cout << questionMap.find(to_string(questionV[i]))->second << endl;
}
return 0;
}