-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
468 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"files.associations": { | ||
"iostream": "cpp", | ||
"ostream": "cpp" | ||
"ostream": "cpp", | ||
"cstring": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int n; | ||
|
||
int main() { | ||
cin >> n; | ||
|
||
int sum = 0; | ||
|
||
for (int i = 1; i <= n; i++) { | ||
int w, score; | ||
cin >> w >> score; | ||
|
||
sum += w * score; | ||
} | ||
|
||
if (sum > 0) cout << sum << endl; | ||
else cout << "0" << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
#include <algorithm> | ||
#include <map> | ||
|
||
#define x first | ||
#define y second | ||
|
||
using namespace std; | ||
|
||
typedef pair<int, int> pii; | ||
int m; | ||
pii p[100010]; | ||
int les[100010]; | ||
int more[100010]; | ||
map<int, int> mp; | ||
map<int, pii> info; | ||
int thres[100010]; | ||
|
||
int main() { | ||
cin >> m; | ||
|
||
for (int i = 1; i <= m; i++) { | ||
int thre, result; | ||
cin >> thre >> result; | ||
p[i] = {thre, result}; | ||
mp[thre] ++; | ||
if (result == 0) info[thre].x ++; | ||
else info[thre].y ++; | ||
} | ||
|
||
sort(p + 1, p + m + 1); | ||
|
||
int n = 1; | ||
for (int i = 1; i <= m; i++) { | ||
if (i == 1) thres[n ++] = p[i].x; | ||
else { | ||
if (p[i].x == p[i - 1].x) continue; | ||
else thres[n ++] = p[i].x; | ||
} | ||
} | ||
|
||
n --; | ||
int cnt = 0; | ||
for (int i = 2; i <= n; i++) { | ||
cnt += info[thres[i - 1]].x; | ||
les[i] = cnt; | ||
} | ||
|
||
cnt = 0; | ||
for (int i = n; i >= 1; i--) { | ||
cnt += info[thres[i]].y; | ||
more[i] = cnt; | ||
} | ||
|
||
int sum = 0, ans; | ||
for (int i = 1; i <= n; i++) { | ||
int cur = les[i] + more[i]; | ||
// cout << i << " : " << les[i] << " " << more[i] << endl; | ||
if (cur >= sum) { | ||
sum = cur; | ||
ans = thres[i]; | ||
} | ||
} | ||
|
||
cout << ans << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// cv | ||
#include <iostream> | ||
#include <cstring> | ||
#include <algorithm> | ||
#include <vector> | ||
#include <set> | ||
|
||
using namespace std; | ||
|
||
typedef long long LL; | ||
const int N = 2000010; | ||
|
||
int n; | ||
struct Node { | ||
string name; | ||
int id, type; // type == 0: 文件夹;type == 1:文件 | ||
mutable LL ld, lr; | ||
mutable LL sd, sr; | ||
bool operator< (const Node& t) const { | ||
return name < t.name; | ||
} | ||
}; | ||
set<Node> son[N]; | ||
int idx; | ||
char str[N]; | ||
bool F; | ||
int U; | ||
LL SZ; | ||
|
||
vector<string> get(char* str) { | ||
vector<string> res(1, "root"); | ||
for (int i = 0; str[i]; i ++ ) { | ||
if (str[i] == '/') continue; | ||
string s; | ||
int j = i; | ||
while (str[j] && str[j] != '/') s += str[j ++ ]; | ||
res.push_back(s); | ||
i = j - 1; | ||
} | ||
|
||
return res; | ||
} | ||
|
||
LL dfs_remove(vector<string>& t, int u, int p) { | ||
string name = t[u]; | ||
if (!son[p].count({name})) return -1; | ||
auto it = son[p].find({name}); | ||
if (u == t.size() - 1) { | ||
if (it->type) t[u] = "#file"; | ||
auto sz = it->sr; | ||
son[p].erase(it); | ||
return sz; | ||
} | ||
if (it->type) return -1; | ||
auto sz = dfs_remove(t, u + 1, it->id); | ||
if (sz >= 0) { | ||
it->sr -= sz; | ||
if (t[u + 1] == "#file") it->sd -= sz; | ||
} | ||
return sz; | ||
} | ||
|
||
bool dfs_create(vector<string>& t, int u, int p, LL sz) { | ||
string name = t[u]; | ||
if (u == t.size() - 1) { | ||
if (son[p].count({name})) { | ||
auto it = son[p].find({name}); | ||
if (it->type == 0) return false; | ||
SZ = dfs_remove(t, 0, 0); | ||
Node cur{name, ++ idx, 1, 0, 0, 0, sz}; | ||
son[p].insert(cur); | ||
return true; | ||
} | ||
else { | ||
Node cur{name, ++ idx, 1, 0, 0, 0, sz}; | ||
son[p].insert(cur); | ||
return true; | ||
} | ||
} | ||
else { | ||
if (!son[p].count({name})) { | ||
if (U == -1) U = u; | ||
Node cur{name, ++ idx, 0, 0, 0, 0, 0}; | ||
son[p].insert(cur); | ||
} | ||
|
||
auto it = son[p].find({name}); | ||
if (it->type) return false; | ||
auto res = dfs_create(t, u + 1, it->id, sz); | ||
if (res) { | ||
it->sr += sz; | ||
if (u + 1 == t.size() - 1) it->sd += sz; | ||
|
||
if (it->lr && it->sr > it->lr) F = false; | ||
if (it->ld && it->sd > it->ld) F = false; | ||
} | ||
return res; | ||
} | ||
} | ||
|
||
bool create(char* str, LL sz) { | ||
auto t = get(str); | ||
F = true, U = -1, SZ = -1; | ||
auto res = dfs_create(t, 0, 0, sz); | ||
|
||
auto ans = res && F; | ||
if (res && !F) { | ||
auto t = get(str); | ||
if (U != -1) { | ||
while (t.size() - 1 > U) t.pop_back(); | ||
} | ||
dfs_remove(t, 0, 0); | ||
if (SZ != -1) create(str, SZ); | ||
} | ||
return ans; | ||
} | ||
|
||
bool update(char* str, LL d, LL r) { | ||
auto t = get(str); | ||
int p = 0; | ||
for (int i = 0; i < t.size(); i ++ ) { | ||
string& s = t[i]; | ||
auto it = son[p].find({s}); | ||
if (it == son[p].end()) return false; | ||
if (it->type) return false; | ||
if (i == t.size() - 1) { | ||
if (d && d < it->sd) return false; | ||
if (r && r < it->sr) return false; | ||
it->ld = d, it->lr = r; | ||
} | ||
p = it->id; | ||
} | ||
return true; | ||
} | ||
|
||
int main() { | ||
scanf("%d", &n); | ||
char op[2]; | ||
sprintf(str, "/tmp"); | ||
create(str, 1); | ||
auto t = get(str); | ||
dfs_remove(t, 0, 0); | ||
while (n -- ) { | ||
scanf("%s", op); | ||
bool res; | ||
if (*op == 'C') { | ||
LL sz; | ||
scanf("%s%lld", str, &sz); | ||
res = create(str, sz); | ||
} | ||
else if (*op == 'R') { | ||
scanf("%s", str); | ||
auto t = get(str); | ||
dfs_remove(t, 0, 0); | ||
res = true; | ||
} | ||
else { | ||
LL d, r; | ||
scanf("%s%lld%lld", str, &d, &r); | ||
res = update(str, d, r); | ||
} | ||
if (res) puts("Y"); | ||
else puts("N"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
#include <algorithm> | ||
|
||
#define x first | ||
#define y second | ||
|
||
using namespace std; | ||
|
||
typedef pair<int, int> PII; | ||
const int N = 110, M = 10, S = 1 << M; | ||
|
||
int n, m, k; | ||
int need[N][M]; | ||
int h[N], e[N * 2], w[N * 2], ne[N * 2], idx; | ||
int d[N][M]; | ||
int f[S], state[N]; | ||
|
||
void add(int a, int b, int c) { | ||
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ; | ||
} | ||
|
||
PII dfs(int u, int fa, int v) { | ||
PII res(0, -1); | ||
if (need[u][v]) res.y = 0; | ||
for (int i = h[u]; ~i; i = ne[i]) { | ||
int j = e[i]; | ||
if (j == fa) continue; | ||
auto t = dfs(j, u, v); | ||
if (t.y != -1) { | ||
res.x += t.x + w[i] * 2; | ||
res.y = max(res.y, t.y + w[i]); | ||
} | ||
} | ||
return res; | ||
} | ||
|
||
bool check(int mid) { | ||
memset(state, 0, sizeof state); | ||
for (int i = 1; i <= n; i ++ ) | ||
for (int j = 0; j < k; j ++ ) | ||
if (d[i][j] <= mid) | ||
state[i] |= 1 << j; | ||
memset(f, 0x3f, sizeof f); | ||
f[0] = 0; | ||
for (int i = 0; i < 1 << k; i ++ ) | ||
for (int j = 1; j <= n; j ++ ) | ||
f[i | state[j]] = min(f[i | state[j]], f[i] + 1); | ||
return f[(1 << k) - 1] <= m; | ||
} | ||
|
||
int main() { | ||
cin >> n >> m >> k; | ||
for (int i = 1; i <= n; i ++ ) | ||
for (int j = 0; j < k; j ++ ) | ||
cin >> need[i][j]; | ||
memset(h, -1, sizeof h); | ||
for (int i = 0; i < n - 1; i ++ ) { | ||
int a, b, c; | ||
scanf("%d%d%d", &a, &b, &c); | ||
add(a, b, c), add(b, a, c); | ||
} | ||
|
||
for (int i = 1; i <= n; i ++ ) | ||
for (int j = 0; j < k; j ++ ) { | ||
auto t = dfs(i, -1, j); | ||
if (t.y != -1) d[i][j] = t.x - t.y; | ||
} | ||
|
||
int l = 0, r = 2e8; | ||
while (l < r) { | ||
int mid = l + r >> 1; | ||
if (check(mid)) r = mid; | ||
else l = mid + 1; | ||
} | ||
|
||
printf("%d\n", r); | ||
return 0; | ||
} |
Oops, something went wrong.