Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 995d69d

Browse files
author
zhunago
committed
拼多多笔试
1 parent 1732273 commit 995d69d

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed

‎nowcoder/hp.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int main(void)
8+
{
9+
int hp, nor, buf;
10+
cin >> hp >> nor >> buf;
11+
int twice = nor * 2;
12+
int step = 0;
13+
while(hp > 0)
14+
{
15+
if(buf > twice && hp > nor)
16+
{
17+
int in = (hp - nor) / buf;
18+
step += in * 2;
19+
hp -= in * buf;
20+
}
21+
else
22+
{
23+
step += 1;
24+
hp -= nor;
25+
}
26+
}
27+
cout << step << endl;
28+
29+
return 0;
30+
}

‎nowcoder/回文序列.cpp‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
int main(void)
7+
{
8+
int n;
9+
cin >> n;
10+
vector<int> input(n, 0);
11+
for(int i = 0; i < n; ++i)
12+
{
13+
cin >> input[i];
14+
}
15+
int i = 0;
16+
int j = n - 1;
17+
int opeC = 0;
18+
while(i < j)
19+
{
20+
if(input[i] == input[j])
21+
{
22+
i++;
23+
j--;
24+
continue;
25+
}
26+
if(input[i] < input[j])
27+
{
28+
input[i+1] += input[i];
29+
i++;
30+
opeC += 1;
31+
}
32+
else
33+
{
34+
input[j-1] += input[j];
35+
j--;
36+
opeC += 1;
37+
}
38+
}
39+
cout << opeC << endl;
40+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <string>
5+
#include <set>
6+
7+
using namespace std;
8+
9+
string dfs(vector<set<char>> &dics, set<string> &s, string &cur, int i)
10+
{
11+
if (i == dics.size())
12+
{
13+
if (s.count(cur) != 0) return "-";
14+
else return cur;
15+
}
16+
for(char c : dics[i])
17+
{
18+
cur.push_back(c);
19+
string ss = dfs(dics, s, cur, i + 1);
20+
if (ss != "-") return ss;
21+
cur.pop_back();
22+
}
23+
return "-";
24+
}
25+
26+
int main(void)
27+
{
28+
int n, m;
29+
cin >> n >> m;
30+
set<string> ss;
31+
vector<set<char>> dics(m);
32+
for(int i = 0; i < n; ++i)
33+
{
34+
string s;
35+
cin >> s;
36+
ss.insert(s);
37+
38+
for(int j = 0; j < m; ++j)
39+
{
40+
dics[j].insert(s[j]);
41+
}
42+
}
43+
string temp = "";
44+
cout << dfs(dics, ss, temp, 0) << endl;
45+
return 0;
46+
}

‎nowcoder/循环小数.cpp‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <string>
5+
#include <unordered_map>
6+
7+
using namespace std;
8+
9+
int main(void)
10+
{
11+
int a, b;
12+
cin >> a >> b;
13+
a = a % b;
14+
unordered_map<int, int> mapp;
15+
mapp[a] = 0;
16+
int step = 0;
17+
while(true)
18+
{
19+
a = a * 10;
20+
a = a % b;
21+
if(a == 0 || mapp.count(a) != 0) break;
22+
23+
step ++;
24+
mapp[a] = step;
25+
}
26+
if(a == 0) cout << step +1 << " " << 0 << endl;
27+
else cout << mapp[a] << " " << step - mapp[a] + 1 << endl;
28+
return 0;
29+
}

‎nowcoder/障碍阻挡小球.cpp‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <string>
5+
#include <list>
6+
7+
using namespace std;
8+
9+
int main(void)
10+
{
11+
int n, m;
12+
cin >> n >> m;
13+
vector<string> qi(n);
14+
for (int i = 0; i < n; ++i)
15+
{
16+
cin >> qi[i];
17+
}
18+
vector<int> summ(n + 1, 0);
19+
vector<int> ob;
20+
ob.push_back(0);
21+
for (int i = 0; i < m; ++i)
22+
{
23+
for (int j = 0; j < n; ++j)
24+
{
25+
summ[j + 1] = summ[j];
26+
if (qi[j][i] == 'o') summ[j + 1] = summ[j] + 1;
27+
else if (qi[j][i] == 'x') ob.push_back(j + 1);
28+
}
29+
if (ob.size() == 1)
30+
{
31+
for (int k = 0; k < n; ++k)
32+
{
33+
qi[k][i] = '.';
34+
}
35+
}
36+
else
37+
{
38+
for (int j = ob.back(); j < n; ++j)
39+
{
40+
qi[j][i] = '.';
41+
}
42+
}
43+
for (int j = ob.size() - 1; j > 0; --j)
44+
{
45+
int box = summ[ob[j]] - summ[ob[j - 1]];
46+
if (box == 0) continue;
47+
for (int k = ob[j] - 1; k > ob[j - 1]; --k)
48+
{
49+
if (box)
50+
{
51+
qi[k - 1][i] = 'o';
52+
box -= 1;
53+
}
54+
else qi[k - 1][i] = '.';
55+
}
56+
}
57+
ob.clear();
58+
ob.push_back(0);
59+
}
60+
for (int i = 0; i < n; ++i)
61+
{
62+
cout << qi[i] << endl;
63+
}
64+
return 0;
65+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /