AtCoderdiverta 2019 Programming Contest
Posted ivorysi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AtCoderdiverta 2019 Programming Contest相关的知识,希望对你有一定的参考价值。
diverta 2019 Programming Contest
因为评测机的缘故……它unrated了。。
A - Consecutive Integers
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,K;
void Solve() {
read(N);read(K);
out(N - K + 1);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
B - RGB Boxes
……
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int R,G,B,N;
void Solve() {
read(R);read(G);read(B);read(N);
int cnt = 0;
for(int i = 0 ; i <= N / R ; ++i) {
int t = N - i * R;
for(int j = 0 ; j <= t / G ; ++j) {
int h = N - i * R - j * G;
if(h % B == 0) ++cnt;
}
}
out(cnt);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
C - AB Substrings
丢人选手交了6遍,罚时+++++
就是记录BA,和只有前面有B,只有后面有A
*A\BA\B*
这样三个拼两个
然后如果只剩*A和B*就都配起来
否则就看一开始是否存在*A和B*,把BA都配起来
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
char s[MAXN];
int a[3];
void Solve() {
read(N);
int ans = 0;
for(int i = 1 ; i <= N ; ++i) {
scanf("%s",s + 1);
int l = strlen(s + 1);
for(int j = 1 ; j < l ; ++j) {
if(s[j] == 'A' && s[j + 1] == 'B') ++ans;
}
if(s[1] == 'B' && s[l] == 'A') ++a[2];
else if(s[1] == 'B') ++a[1];
else if(s[l] == 'A') ++a[0];
}
int t = min(a[2],min(a[0],a[1]));
ans += t * 2;
a[2] -= t;a[0] -= t;a[1] -= t;
ans += min(a[0],a[1]);
if(a[2]) {
if(t) ans += a[2];
else if(max(a[0],a[1])) ans += a[2];
else ans += a[2] - 1;
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
D - DivRem Number
\(\lfloor \frac{N}{i} \rfloor\)只有\(\sqrt{N}\)种取值,枚举出来求出m然后看m在不在对应区间即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int64 N;
void Solve() {
read(N);
int64 ans = 0;
for(int64 i = 1 ; i <= N ; ++i) {
int64 r = N / (N / i);
int64 t = N / i;
if(N % t == 0) {
int64 k = N / t - 1;
if(k >= i && k <= r) ans += k;
}
i = r;
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
E - XOR Partitioning
如果一段不为0的话,那么这些位置的前缀和肯定是a0a0a0a0,这样的话就\(dp[i]\)表示这个数为结尾,然后找前一段和它相同的\(dp[j]\)且\(s[i] == s[j]\),转移乘上中间所有的0的个数,可以通过拆成前缀和分项维护
最后计算每一段为0的方案数
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int MOD = 1000000007;
int N;
int A[MAXN],sum[MAXN],s[MAXN];
int pre[2][(1 << 20) + 5],dp[MAXN];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(A[i]);
s[i] = s[i - 1] ^ A[i];
sum[i] = sum[i - 1] + (s[i] == 0);
}
int all = 0;
for(int i = 1 ; i <= N ; ++i) {
if(s[i] != 0) {
dp[i] = mul(pre[0][s[i]],sum[i - 1]) + 1;
update(dp[i],MOD - pre[1][s[i]]);
}
else dp[i] = inc(all,MOD - pre[0][0]);
update(pre[0][s[i]],dp[i]);
update(pre[1][s[i]],mul(dp[i],sum[i]));
update(all,dp[i]);
}
if(s[N] == 0) {
update(dp[N],fpow(2,sum[N] - 1));
}
out(dp[N] % MOD);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
F - Edge Ordering
假如树边的大小固定了,那么非树边的必须大于树边中最大的那条
如果我们认为非树边是白球,树边是黑球,就是先填被最大的边控制的白球,然后填最大的黑球,填被次大的边控制的白球,填次大的黑球……
这个序列应该是来了白球可以在任意位置,来了黑球必须放到序列最前面
那么怎么统计价值和呢,记录序列长度n,序列种类c,黑球个数b,和价值和s
如果来了一个黑球
\((n,c,b,s)\rightarrow (n + 1,c,b + 1,s + (b +1)c)\)
如果来了一个白球
\((n,c,b,s)\rightarrow(n + 1,c(n +1),b,s(n + 2))\)
为啥是\(n + 2\)呢。。因为如果把那个白球从前移到后,会发现\(s\)被加了\((n +1)\)次,余下的零头是原来所有黑球的坐标和
然后如果来了k个白球
\((n,c,b,s) \rightarrow (n + k,c(n + 1)(n + 2)\cdots(n + k),b,s(n + 2)(n + 3)\cdots(n + k + 1))\)
那么又回到刚开始的假设了,如何确定树边的大小呢
可以用dp从大到小分配每个树边
设S表示集合为S的树边已经被固定了
每次新加一条树边控制的非树边,是加之后非树边的两个点连通的非树边的个数,减掉加之前非树边两个点连通非树边的个数
这个只要对于每一种边集连起来,然后搜出每个联通块,计算联通块之间边相连的数目再减去联通块里树边的数目即可
联通块里边的数目可以很容易通过dp算出
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M;
int a[205],b[205],fac[205],invfac[205];
int col[(1 << 20) + 5][21],num[(1 << 20) + 5],c[21];
int to[21],e[(1 << 20) + 5],cnt[(1 << 20) + 5];
int dp[(1 << 19) + 5],sum[(1 << 19) + 5],len[(1 << 19) + 5];
int fa[21];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
int lowbit(int x) {
return x & (-x);
}
int getfa(int x) {
return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
void Solve() {
read(N);read(M);
for(int i = 1 ; i <= M ; ++i) {
read(a[i]);read(b[i]);
to[a[i]] |= (1 << b[i] - 1);
to[b[i]] |= (1 << a[i] - 1);
}
fac[0] = 1;
for(int i = 1 ; i <= 200 ; ++i) fac[i] = mul(fac[i - 1],i);
invfac[200] = fpow(fac[200],MOD - 2);
for(int i = 199 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
for(int S = 0 ; S < (1 << N) ; ++S) {
if(S != 0) cnt[S] = cnt[S - lowbit(S)] + 1;
for(int j = 1 ; j <= N ; ++j) {
if(S >> (j - 1) & 1) {
int T = to[j] & S;
e[S] = e[S ^ (1 << j - 1)] + cnt[T];break;
}
}
}
for(int S = 0 ; S < (1 << N - 1) ; ++S) {
for(int i = 1 ; i <= N ; ++i) fa[i] = i;
for(int i = 1 ; i < N ; ++i) {
if(S >> (i - 1) & 1) {
fa[getfa(a[i])] = getfa(b[i]);
}
}
int tot = 0;
for(int i = 1 ; i <= N ; ++i) {
if(fa[i] == i) {col[S][i] = ++tot;c[tot] = 0;}
}
for(int i = 1 ; i <= N ; ++i) {
col[S][i] = col[S][getfa(i)];
int t = col[S][i];
c[t] |= (1 << i - 1);
}
for(int i = 1 ; i <= tot ; ++i) {
num[S] += e[c[i]] - (cnt[c[i]] - 1);
}
}
dp[0] = 1;sum[0] = 0;
int ALL = (1 << N - 1) - 1;
for(int S = 0 ; S < (1 << N - 1) ; ++S) {
for(int j = 1 ; j < N ; ++j) {
if(!(S >> (j - 1) & 1)) {
int a = num[ALL ^ S] - num[ALL ^ S ^ (1 << j - 1)];
int T = S ^ (1 << j - 1);
int n = len[S];
len[T] = n + a + 1;
int c = mul(dp[S],mul(fac[n + a],invfac[n]));
int s = mul(sum[S],mul(fac[n + a + 1],invfac[n + 1]));
update(s,mul(c,cnt[S] + 1));
update(dp[T],c);update(sum[T],s);
}
}
}
out(sum[(1 << N - 1) - 1]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
以上是关于AtCoderdiverta 2019 Programming Contest的主要内容,如果未能解决你的问题,请参考以下文章
configuration.getValue 或 configuration.getsection 总是返回 null
如何通过具有命令行参数的 procdump 启动 Windows 应用程序?