Thu, 28 Mar 2019 15:53:50 +0800
parent
b7f1aa97d6
commit
7a03e71fa1
@ -0,0 +1,43 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e5 + 50;
|
||||
struct num {
|
||||
int x;
|
||||
int id;
|
||||
} ns[N];
|
||||
|
||||
bool cmp(num a, num b) {
|
||||
if (a.x == b.x)return a.id < b.id;
|
||||
else return a.x > b.x;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int T, n;
|
||||
scanf("%d", &T);
|
||||
while (T--) {
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
scanf("%d", &ns[i].x);
|
||||
ns[i].id = i;
|
||||
}
|
||||
|
||||
sort(ns + 1, ns + 1 + n, cmp);
|
||||
bool fl = 1;
|
||||
for (int i = 2; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (ns[j].id % i != 0) {
|
||||
if (fl) {
|
||||
printf("%d", ns[j].x);
|
||||
fl = 0;
|
||||
} else printf(" %d", ns[j].x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int T, n, a, b, c, d, e, f, g;
|
||||
scanf("%d", &T);
|
||||
while (T--) {
|
||||
scanf("%d", &n);
|
||||
int ans = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g);
|
||||
if (a - d - f + g < 0) continue;
|
||||
if (b - d - e + g < 0) continue;
|
||||
if (c - f - e + g < 0) continue;
|
||||
if (g > e) continue;
|
||||
if (g > f) continue;
|
||||
if (g > d) continue;
|
||||
if (d > a) continue;
|
||||
if (d > b) continue;
|
||||
if (e > b) continue;
|
||||
if (e > c) continue;
|
||||
if (f > a) continue;
|
||||
if (f > c) continue;
|
||||
ans = max(ans, a + b + c - d - f - e + g);
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int T, n;
|
||||
scanf("%d", &T);
|
||||
while (T--) {
|
||||
scanf("%d", &n);
|
||||
printf("%d\n", (n - 1) / 2 + 2);
|
||||
}
|
||||
/*
|
||||
int n;
|
||||
set<int> S;
|
||||
for (n = 1; n < 100; n++) {
|
||||
S.clear();
|
||||
for (int i = 1; i <= n + 1; i++)
|
||||
S.insert(n % i);
|
||||
cout << (n - 1) / 2 + 2 << " " << S.size() << endl;
|
||||
for (auto x:S)
|
||||
cout << x << " ";
|
||||
cout << endl;
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
add_executable(A A.cpp)
|
||||
add_executable(B B.cpp)
|
||||
add_executable(C C.cpp)
|
||||
add_executable(D D.cpp)
|
||||
add_executable(E E.cpp)
|
||||
add_executable(J J.cpp)
|
||||
@ -0,0 +1,23 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 50;
|
||||
int a[N];
|
||||
|
||||
int main() {
|
||||
a[1] = 1, a[2] = a[3] = 2;
|
||||
int grp = 3, prev = 2;
|
||||
for (int i = 4; i < N; grp++)
|
||||
for (int j = 1; j <= a[grp]; j++, i++) {
|
||||
a[i] = 3 - prev;
|
||||
if (j == a[grp])
|
||||
prev = a[i];
|
||||
}
|
||||
int T, n;
|
||||
scanf("%d", &T);
|
||||
while (T--) {
|
||||
scanf("%d", &n);
|
||||
printf("%d\n", a[n]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 10100;
|
||||
char s[N];
|
||||
int a[N];
|
||||
|
||||
int main() {
|
||||
int T, m;
|
||||
scanf("%d", &T);
|
||||
while (T--) {
|
||||
scanf("%d%s", &m, s);
|
||||
int len = strlen(s);
|
||||
int ans = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
int r = min(i, len - i - 1);
|
||||
for (int j = 1; j <= r; j++)
|
||||
a[j] = a[j - 1] + abs(s[i - j] - s[i + j]);
|
||||
for (int k = 0, j = 0, d = 0; k <= r; k++) {
|
||||
d = a[k] - a[j];
|
||||
while (d > m) d = a[k] - a[++j];
|
||||
ans = max(ans, k - j);
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < len; i++) {
|
||||
int r = min(i, len - i);
|
||||
for (int j = 1; j <= r; j++)
|
||||
a[j] = a[j - 1] + abs(s[i - j] - s[i + j - 1]);
|
||||
for (int k = 0, j = 0, d = 0; k <= r; k++) {
|
||||
d = a[k] - a[j];
|
||||
while (d > m) d = a[k] - a[++j];
|
||||
ans = max(ans, k - j);
|
||||
}
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
string s;
|
||||
cin >> n >> s;
|
||||
unsigned long long ans = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
if (((s[i] - '0') & 1) ^ 1)
|
||||
ans += i + 1;
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 2e5 + 5;
|
||||
long long a[N];
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++) scanf("%lld", a + i);
|
||||
long long ans = 0, cut = numeric_limits<long long>::max();
|
||||
for (int i = n - 1; i >= 0; i--) {
|
||||
cut = min(cut - 1, a[i]);
|
||||
if (cut <= 0) break;
|
||||
ans += cut;
|
||||
}
|
||||
printf("%lld", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 2e5 + 5;
|
||||
const long long mod = 1e9 + 7;
|
||||
int adj[N], nxt[N], to[N], col[N], ecnt;
|
||||
|
||||
inline void addEdge(int f, int t, int c) {
|
||||
ecnt++;
|
||||
nxt[ecnt] = adj[f];
|
||||
adj[f] = ecnt;
|
||||
to[ecnt] = t;
|
||||
col[ecnt] = c;
|
||||
}
|
||||
|
||||
using ll=long long;
|
||||
|
||||
ll qpow(ll a, ll b) {
|
||||
ll ans = 1;
|
||||
for (; b; b >>= 1, a = a * a % mod)
|
||||
if (b & 1)
|
||||
ans = ans * a % mod;
|
||||
return ans;
|
||||
}
|
||||
|
||||
bool vis[N];
|
||||
long long m;
|
||||
|
||||
void dfs(int x) {
|
||||
vis[x] = true;
|
||||
for (int e = adj[x]; e; e = nxt[e])
|
||||
if (col[e] == 0 && !vis[to[e]])
|
||||
m++, dfs(to[e]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
long long n, k;
|
||||
scanf("%lld%lld", &n, &k);
|
||||
for (int i = 1, u, v, w; i < n; i++) {
|
||||
scanf("%d%d%d", &u, &v, &w);
|
||||
addEdge(u, v, w);
|
||||
addEdge(v, u, w);
|
||||
}
|
||||
|
||||
long long ans = qpow(n, k);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!vis[i]) {
|
||||
vis[i] = true;
|
||||
m = 1;
|
||||
dfs(i);
|
||||
ans = (ans - qpow(m, k) + mod) % mod;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%lld\n", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
add_executable(A A.cpp)
|
||||
add_executable(B B.cpp)
|
||||
add_executable(C C.cpp)
|
||||
@ -0,0 +1,18 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
char s[1010];
|
||||
int main()
|
||||
{
|
||||
int T, n;
|
||||
scanf("%d", &T);
|
||||
while (T--)
|
||||
{
|
||||
scanf("%d%s", &n, s);
|
||||
int ans = n - 1;
|
||||
for (int i = 0; i < n; ++i)
|
||||
if (s[i] == '>' || s[n - 1 - i] == '<')
|
||||
ans = min(ans, i);
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 3e5 + 50;
|
||||
pair<int, int> a[N];
|
||||
int main()
|
||||
{
|
||||
int n, k;
|
||||
scanf("%d%d", &n, &k);
|
||||
for (int i = 0; i < n; i++)
|
||||
scanf("%d%d", &a[i].second, &a[i].first);
|
||||
sort(a, a + n);
|
||||
multiset<int> lens;
|
||||
long long sum = 0, ans = 0;
|
||||
for (int i = n - 1; i >= 0; i--)
|
||||
{
|
||||
lens.insert(a[i].second);
|
||||
sum += a[i].second;
|
||||
while (lens.size() > k)
|
||||
{
|
||||
auto ite = lens.begin();
|
||||
sum -= *ite;
|
||||
lens.erase(ite);
|
||||
}
|
||||
ans = max(ans, sum * a[i].first);
|
||||
}
|
||||
printf("%lld", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
long long ans = 0;
|
||||
for (int id = 2; id < n; id++)
|
||||
ans += id * (id + 1ll);
|
||||
printf("%lld", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
add_executable(A A.cpp)
|
||||
add_executable(B B.cpp)
|
||||
add_executable(C C.cpp)
|
||||
Loading…
Reference in new issue