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 3e502fe

Browse files
author
zhunago
committed
迅雷
1 parent 4dffb76 commit 3e502fe

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

‎nowcoder/xunlei1.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
3+
num = [int(elem) for elem in sys.stdin.readline().strip().split(",")]
4+
sumforward = [0 for i in range(len(num) + 1)]
5+
sumbackwad = [0 for i in range(len(num) + 1)]
6+
7+
ss = 0
8+
9+
10+
for i in range(len(num)):
11+
sumforward[i + 1] = sumforward[i] + num[i]
12+
i = len(num)
13+
while(i > 0):
14+
sumbackwad[i-1] = sumbackwad[i] + num[i - 1]
15+
i -=1
16+
17+
hasresult = False
18+
for i in range(len(num)):
19+
if(sumforward[i] == sumbackwad[i + 1]):
20+
print(num[i])
21+
hasresult = True
22+
break
23+
24+
if not hasresult:
25+
print("False")

‎nowcoder/xunlei2.cpp‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <queue>
5+
#include <sstream>
6+
7+
using namespace std;
8+
9+
int main(void)
10+
{
11+
vector<int> a;
12+
vector<int> b;
13+
int temp;
14+
char c;
15+
while(cin >> temp)
16+
{
17+
a.push_back(temp);
18+
cin >> c;
19+
if(c == '-') break;
20+
}
21+
while(cin >> temp)
22+
{
23+
b.push_back(temp);
24+
cin >> c;
25+
if(c == ':') break;
26+
}
27+
int k;
28+
cin >> k;
29+
30+
sort(a.begin(), a.end(), [](int ta, int tb){return ta > tb;});
31+
sort(b.begin(), b.end(), [](int ta, int tb){return ta > tb;});
32+
33+
auto comp = [&](const vector<int>& a, const vector<int>& b) {
34+
return a.back() < b.back();
35+
};
36+
typedef priority_queue<vector<int>, vector<vector<int>>, decltype(comp)> pq_t;
37+
pq_t pq(comp);
38+
for(int i = 0; i < b.size(); ++i)
39+
{
40+
pq.push({i, 0, b[i] + a[0]});
41+
}
42+
43+
int count = 0;
44+
stringstream ss;
45+
while(!pq.empty())
46+
{
47+
const vector<int> &curMax = pq.top();
48+
int ib = curMax[0];
49+
int ia = curMax[1];
50+
pq.pop();
51+
int temp = 0;
52+
int i = 0;
53+
for(i = ia; i < a.size(); ++i)
54+
{
55+
temp = b[ib] + a[i];
56+
if(temp >= pq.top()[2])
57+
{
58+
ss << temp << ',';
59+
count += 1;
60+
if(count == k)
61+
{
62+
break;
63+
}
64+
}
65+
else
66+
{
67+
pq.push({ib, i, temp});
68+
break;
69+
}
70+
}
71+
if(count == k) break;
72+
}
73+
string result = ss.str();
74+
cout << result.substr(0, result.size() - 1) << endl;
75+
return 0;
76+
}

0 commit comments

Comments
(0)

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