Tue, 06 Aug 2019 15:12:42 +0800

master
大蒟蒻 6 years ago
parent e9144f1124
commit 378666eaf5

@ -0,0 +1,15 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int main()
{
return 0;
}

@ -0,0 +1,15 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int main()
{
return 0;
}

@ -0,0 +1,15 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int main()
{
return 0;
}

@ -0,0 +1,70 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
const int N = 1e5 + 50;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
struct node
{
ll a, b;
OPL(node, rhs) { return b * rhs.a > a * rhs.b; }
void neg() { a = -a, b = -b; }
} p[N];
struct ans
{
ll h, l;
OPL(ans, rhs) { return h * rhs.l < l * rhs.h; }
void simp()
{
if (h == 0) return void(l = 1);
if (l < 0) h = -h, l = -l;
int g = gcd(abs(h), l);
h /= g, l /= g;
}
};
int main()
{
set<ans> S;
int T, n, c;
scanf("%d", &T);
while (T--)
{
S.clear();
scanf("%d%d", &n, &c);
int suma = 0, sumb = 0;
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &p[i].a, &p[i].b), suma -= p[i].a, sumb -= p[i].b;
p[0] = {1, 100000000ll}, p[n + 1] = {1, -100000000ll};
sort(p + 1, p + n + 1);
bool flag = false;
for (int i = 1; i <= n + 1; i++)
{
if (suma == 0)
{
flag = true;
break;
}
ans cur = {c - sumb, suma};
cur.simp();
if (p[i - 1].a * cur.h + p[i - 1].b * cur.l >= 0 && p[i].a * cur.h + p[i].b * cur.l <= 0)
S.insert(cur);
suma += p[i].a << 1, sumb += p[i].b << 1;
}
if (flag)
puts("-1");
else
{
printf("%d", (int)S.size());
for (auto &x : S) printf(" %lld/%lld", x.h, x.l);
putchar('\n');
}
}
return 0;
}

@ -0,0 +1,81 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int a[1005];
struct MyStruct
{
int a[21], n;
OPL(MyStruct, rhs)
{
auto b = rhs.a;
for (int i = 1; i < n; i++)
{
if (a[i] - a[i - 1] < b[i] - b[i - 1]) return true;
if (a[i] - a[i - 1] > b[i] - b[i - 1]) return false;
}
return false;
}
} arr[362881];
int main()
{
int T, n, k;
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &k);
if (n <= 9)
{
for (int i = 0; i < n; i++) a[i] = i + 1;
int cnt = 0;
do
{
memcpy(arr[cnt].a, a, n << 2);
arr[cnt].n = n;
cnt++;
/*for (int i = 0; i < n; i++)
printf("%2d%c", a[i], " \n"[i == n - 1]);
printf(" ");
for (int i = 1; i < n; i++)
printf("%2d%c", a[i] - a[i - 1], " \n"[i == n - 1]);
putchar('\n');*/
} while (next_permutation(a, a + n));
sort(arr, arr + cnt);
/*
for (int i = 0; i < cnt; i++)
{
auto a = arr[i].a;
for (int i = 0; i < n; i++)
printf("%2d%c", a[i], " \n"[i == n - 1]);
printf(" ");
for (int i = 1; i < n; i++)
printf("%2d%c", a[i] - a[i - 1], " \n"[i == n - 1]);
putchar('\n');
}*/
auto a = arr[k - 1].a;
for (int i = 0; i < n; i++) printf("%d%c", a[i], " \n"[i == n - 1]);
}
else
{
a[0] = n;
for (int i = 1; i < n; i++) a[i] = i;
int cnt = 0;
do
{
//memcpy(arr[cnt].a, a, n << 2);
//arr[cnt].n = n;
cnt++;
if (cnt == k) break;
} while (next_permutation(a, a + n));
for (int i = 0; i < n; i++) printf("%d%c", a[i], " \n"[i == n - 1]);
}
}
return 0;
}

Binary file not shown.

Binary file not shown.

@ -0,0 +1,111 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef int64_t ll, i64;
typedef uint64_t ull, u64;
const int N = 1e6 + 50;
int extend[N], nxt[N];
void exkmp(char *s, char *t)
{
int slen, tlen, a = 0, i, l, p, j;
slen = strlen(s);
tlen = strlen(t);
nxt[0] = tlen; //ÇónextÊý×é
while (a < tlen - 1 && t[a] == t[a + 1]) a++;
nxt[1] = a;
a = 1;
for (i = 2; i < tlen; i++)
{
p = a + nxt[a] - 1;
l = nxt[i - a];
if (i + l - 1 >= p)
{
j = (p - i + 1) > 0 ? p - i + 1 : 0;
while (i + j < tlen && t[i + j] == t[j]) j++;
nxt[i] = j;
a = i;
}
else
nxt[i] = l;
} //ÇóextendÊý×é
a = 0;
while (a < tlen && a < slen && t[a] == s[a]) a++;
extend[0] = a;
a = 0;
for (i = 1; i < slen; i++)
{
p = a + extend[a] - 1;
l = nxt[i - a];
if (i + l - 1 >= p)
{
j = (p - i + 1) > 0 ? p - i + 1 : 0;
while (i + j < slen && j < tlen && s[i + j] == t[j]) j++;
extend[i] = j;
a = i;
}
else
extend[i] = l;
}
}
char s[N];
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%s", s);
exkmp(s, s);
int len = strlen(s);
ll ans = 0;
for (int i = 1; i < len; i++)
{
//printf("%2d%c", extend[i], " \n"[i == len - 1]);
ans += extend[i] + (i + extend[i] < len);
//if (i + extend[i] < len) ans++;
}
printf("%lld\n", ans);
}
return 0;
}
//int main()
//{
// char s[N];
// ull hs[N], b[N];
// for (int i = *b = 1; i < N; i++) b[i] = b[i - 1] * 131;
// int T;
// scanf("%d", &T);
// while (T--)
// {
// scanf("%s", s + 1);
// // int len = strlen(s + 1);
// // for (int i = 1; i <= len; i++) hs[i] = hs[i - 1] * 131 + s[i];
// int len = 0;
// for (char *p = s + 1; *p; len++) hs[len + 1] = hs[len] * 131 + *p++;
// ull ans = 0;
// for (int i = 2; i <= len; i++)
// {
// int L = i, R = len + 1, M = L;
// while (L < R - 1)
// {
// M = (L + R) >> 1;
// // ull hs1 = hs[M - i + 1];
// // ull hs2 = hs[M] - hs[i - 1] * b[M - i + 1];
// if (hs[M - i + 1] == hs[M] - hs[i - 1] * b[M - i + 1])
// L = M;
// else
// R = M;
// }
// ans += L - i + 1 + ((L != i || s[1] == s[L]) && L < len);
// }
// printf("%llu\n", ans);
// }
// return 0;
//}

File diff suppressed because one or more lines are too long

@ -0,0 +1,4 @@
s = 'a' * int(1e6)
print(30)
for _ in range(30):
print(s)

@ -0,0 +1,40 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
const int N = 1000;
int a[N], n, x, y, cnt;
bool b[N];
void dfs(int st)
{
if (st == n)
{
for (int i = 0; i < n; i++) printf("%2d%c", a[i], " \n"[i == n - 1]);
cnt++;
}
else
{
if (st == 0)
b[a[st] = x] = true, dfs(st + 1), b[x] = false;
else if (st == n - 1)
{
if (!b[y] && abs(y - a[st - 1]) <= 2) b[a[st] = y] = true, dfs(st + 1), b[y] = false;
}
else
for (int i = 1; i <= n; i++)
if (i != x && i != y && !b[i] && abs(i - a[st - 1]) <= 2)
b[a[st] = i] = true, dfs(st + 1), b[i] = false;
}
}
int main()
{
for (; ~scanf("%d%d%d", &n, &x, &y); printf(":%d\n", cnt)) dfs(cnt = 0);
return 0;
}

@ -0,0 +1,15 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int main()
{
return 0;
}

@ -0,0 +1,15 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int main()
{
return 0;
}

@ -0,0 +1,15 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int main()
{
return 0;
}

@ -0,0 +1,15 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
int main()
{
return 0;
}

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
add_compile_options("/Zc:__cplusplus")
endif()
include_directories("D:\\PortableApps\\MSYS2\\mingw64\\include\\c++\\9.1.0\\x86_64-w64-mingw32")
add_executable(01 01.cpp)
add_executable(02 02.cpp)
add_executable(03 03.cpp)
add_executable(04 04.cpp)
add_executable(05 05.cpp)
add_executable(06 06.cpp)
add_executable(07 07.cpp)
add_executable(08 08.cpp)
add_executable(09 09.cpp)
add_executable(10 10.cpp)
add_executable(11 11.cpp)

@ -9,7 +9,58 @@ using namespace std;
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
const int N = 1e5 + 40;
char buf[N];
#define ID(ch, po) ((ch - 'a') * N + po)
struct Edge
{
int nxt, to;
} E[N * 10];
int adj[N * 10], ecnt, in[N * 10];
inline void addEdge(int f, int t)
{
if (in[f] == -1) in[f] = 0;
if (in[t] == -1) in[t] = 0;
E[++ecnt] = {adj[f], t};
adj[f] = ecnt;
in[t]++;
}
int main()
{
NE1(in);
int n, m, mm, l;
scanf("%d%d", &n, &m), mm = m * (m - 1) / 2;
for (int i = 0; i < mm; i++)
{
scanf("%s%d", buf, &l);
int cnt[] = {0, 1};
if (l)
{
scanf("%s", buf);
for (int j = 1; j < l; j++)
{
int type1 = buf[j - 1] == *buf;
int type2 = buf[j] == *buf;
cnt[type2]++;
addEdge(ID(buf[j - 1], cnt[type1] - (buf[j - 1] == buf[j])), ID(buf[j], cnt[type2]));
}
}
}
vector<char> ans;
ans.reserve(n);
queue<int> Q;
for (int i = 0; i < N * 10; i++)
if (in[i] == 0) Q.push(i);
for (; !Q.empty(); Q.pop())
{
ans.push_back(Q.front() / N + 'a');
for (int e = adj[Q.front()]; e; e = E[e].nxt)
if (--in[E[e].to] == 0)
Q.push(E[e].to);
}
if (ans.size() != n)
puts("-1");
else
ans.push_back(0), puts(ans.data());
return 0;
}

@ -11,5 +11,6 @@ using namespace std;
typedef long long ll, i64;
int main()
{
return 0;
}

@ -26,14 +26,7 @@ int main()
{
puts("Yes");
FIL(G, '0');
for (int i = 1; i < n; i += 3)
for (int j = 0; i + j < n; j++)
G[j][i + j] = '1';
for (int i = 1; i < n; i += 3)
for (int j = 0; i + j < n; j++)
G[i + j][j] = '1';
for (int i = 0; i + i < n; i++) mp[i] = (i + 1) << 1;
for (int i = n / 2; i < n; i++) mp[i] = (i - n / 2) << 1 | 1;
for (int i = 0; i < n; i++) G[i][n] = 0, puts(G[i]);
for (int i = 0; i < n; i++) printf("%d%c", mp[i], " \n"[i == n - 1]);
}

Loading…
Cancel
Save