Compare commits
10
Commits
ff723f978a
...
eb7a278b1b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb7a278b1b | ||
|
|
daa97afaae | ||
|
|
124a3e999e | ||
|
|
f025899392 | ||
|
|
ac8093b43e | ||
|
|
785c9dcea8 | ||
|
|
1f71aab9ff | ||
|
|
3d6265ac1c | ||
|
|
58c77f67e8 | ||
|
|
51224a7941 |
+2
-1
@@ -4,4 +4,5 @@
|
||||
!.vscode/
|
||||
!.vscode/*
|
||||
!ac-congrats.png
|
||||
!README.md
|
||||
!README.md
|
||||
!0x*
|
||||
@@ -0,0 +1 @@
|
||||
// 98
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// 115 not finished
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int n;
|
||||
int a[1005];
|
||||
int fa[1005];
|
||||
int dt[1005];
|
||||
int root;
|
||||
vector<int> chi[1005];
|
||||
bool ran[1005];
|
||||
int ans, T;
|
||||
void dfs(int now) // 染色到dt[now]
|
||||
{
|
||||
if (dt[now] == root)
|
||||
{
|
||||
ran[now] = 1, ans += (T++) * a[dt[now]];
|
||||
return;
|
||||
}
|
||||
if (!ran[fa[dt[now]]])
|
||||
dfs(fa[dt[now]]);
|
||||
ran[now] = 1, ans += (T++) * a[dt[now]];
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; ++i)
|
||||
scanf("%d", &a[i]), dt[i] = i;
|
||||
sort(dt + 1, dt + n + 1, [](int x, int y)
|
||||
{ return a[x] < a[y]; });
|
||||
for (int u, v, i = 1; i < n; ++i)
|
||||
scanf("%d%d", &u, &v),
|
||||
fa[v] = u, chi[u].push_back(v);
|
||||
for (int i = 1; i <= n; ++i)
|
||||
{
|
||||
if (fa[i] == i)
|
||||
{
|
||||
root = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= n; ++i)
|
||||
{
|
||||
dfs(i);
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// 119
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// 126
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int n, m, k, a[105][105], sum[105][105];
|
||||
int query(int xx1, int yy1, int xx2, int yy2)
|
||||
{
|
||||
return sum[xx2][yy2] - sum[xx1 - 1][yy2] - sum[xx2][yy1 - 1] + sum[xx1 - 1][yy1 - 1];
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; ++i)
|
||||
for (int j = 1; j <= n; ++j)
|
||||
scanf("%d", &a[i][j]), sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
|
||||
int ans = -2147482648;
|
||||
for (int xx1 = 1; xx1 <= n; ++xx1)
|
||||
for (int yy1 = 1; yy1 <= n; ++yy1)
|
||||
for (int xx2 = xx1; xx2 <= n; ++xx2)
|
||||
for (int yy2 = yy1; yy2 <= n; ++yy2)
|
||||
if (query(xx1, yy1, xx2, yy2) > ans)
|
||||
ans = query(xx1, yy1, xx2, yy2);
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// 127
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int n, m;
|
||||
pair<int, int> rob[100005], task[100005];
|
||||
int c[105];
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1; i <= n; ++i)
|
||||
scanf("%d%d", &rob[i].first, &rob[i].second);
|
||||
for (int i = 1; i <= m; ++i)
|
||||
scanf("%d%d", &task[i].first, &task[i].second);
|
||||
sort(rob + 1, rob + n + 1, [](pair<int, int> a, pair<int, int> b)
|
||||
{ return (a.first == b.first) ? a.second > b.second : a.first > b.first; });
|
||||
sort(task + 1, task + m + 1, [](pair<int, int> a, pair<int, int> b)
|
||||
{ return (a.first == b.first) ? a.second > b.second : a.first > b.first; });
|
||||
int p = 0;
|
||||
int cnt = 0;
|
||||
long long ans = 0;
|
||||
for (int i = 1; i <= m; ++i)
|
||||
{
|
||||
while (p < n && rob[p + 1].first >= task[i].first)
|
||||
p++, c[rob[p].second]++;
|
||||
for (int j = task[i].second; j <= 100; j++)
|
||||
if (c[j])
|
||||
{
|
||||
cnt++, c[j]--, ans += task[i].first * 500 + task[i].second * 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("%d %lld\n", cnt, ans);
|
||||
return 0;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// 41
|
||||
class MinStack
|
||||
{
|
||||
public:
|
||||
/** initialize your data structure here. */
|
||||
int a[105], tot = 0;
|
||||
MinStack()
|
||||
{
|
||||
}
|
||||
void push(int x)
|
||||
{
|
||||
a[++tot] = x;
|
||||
}
|
||||
void pop()
|
||||
{
|
||||
tot--;
|
||||
}
|
||||
int top()
|
||||
{
|
||||
return a[tot];
|
||||
}
|
||||
int getMin()
|
||||
{
|
||||
int ans = 1e9;
|
||||
for (int i = tot; i >= 1; i--)
|
||||
ans = (a[i] < ans) ? a[i] : ans;
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Your MinStack object will be instantiated and called as such:
|
||||
* MinStack obj = new MinStack();
|
||||
* obj.push(x);
|
||||
* obj.pop();
|
||||
* int param_3 = obj.top();
|
||||
* int param_4 = obj.getMin();
|
||||
*/
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
// 128
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int q;
|
||||
int qjh[1000005];
|
||||
int ans[1000005];
|
||||
vector<int> s, tmp;
|
||||
int main()
|
||||
{
|
||||
cin >> q;
|
||||
for (int i = 0; i <= q + 1; ++i)
|
||||
ans[i] = INT_MIN;
|
||||
while (q--)
|
||||
{
|
||||
char c;
|
||||
cin >> c;
|
||||
if (c == 'I')
|
||||
{
|
||||
int x;
|
||||
cin >> x;
|
||||
s.push_back(x);
|
||||
qjh[s.size()] = qjh[s.size() - 1] + x;
|
||||
ans[s.size()] = max(ans[s.size() - 1], qjh[s.size()]);
|
||||
}
|
||||
else if (c == 'D')
|
||||
{
|
||||
if (!s.empty())
|
||||
s.pop_back();
|
||||
}
|
||||
else if (c == 'L')
|
||||
{
|
||||
if (!s.empty())
|
||||
{
|
||||
tmp.push_back(s[s.size() - 1]);
|
||||
s.pop_back();
|
||||
}
|
||||
}
|
||||
else if (c == 'R')
|
||||
{
|
||||
if (!tmp.empty())
|
||||
{
|
||||
s.push_back(tmp[tmp.size() - 1]);
|
||||
qjh[s.size()] = qjh[s.size() - 1] + tmp[tmp.size() - 1];
|
||||
ans[s.size()] = max(ans[s.size() - 1], qjh[s.size()]);
|
||||
tmp.pop_back();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int x;
|
||||
cin >> x;
|
||||
cout << ans[x] << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// 129
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
vector<int> ans;
|
||||
int stk[25], tot, n, cnt;
|
||||
void dfs(int now)
|
||||
{
|
||||
if (cnt >= 20)
|
||||
return;
|
||||
if (now > n)
|
||||
{
|
||||
cnt++;
|
||||
for (auto x : ans)
|
||||
cout << x;
|
||||
for (int i = tot - 1; i >= 0; i--)
|
||||
cout << stk[i];
|
||||
puts("");
|
||||
return;
|
||||
}
|
||||
if (tot)
|
||||
{
|
||||
ans.push_back(stk[--tot]);
|
||||
dfs(now);
|
||||
stk[tot++] = ans.back();
|
||||
ans.pop_back();
|
||||
}
|
||||
stk[tot++] = now;
|
||||
dfs(now + 1);
|
||||
tot--;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cin >> n;
|
||||
dfs(1);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user