A - Beginning
这个年份恐怕需要+2
#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 MAXN 80005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
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 num[10];
void Solve() {
for(int i = 1 ; i <= 4 ; ++i) read(num[i]);
sort(num + 1,num + 5);
if(num[1] == 1 && num[2] == 4 && num[3] == 7 && num[4] == 9) {puts("YES");}
else puts("NO");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
B - KEYENCE String
……
#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 MAXN 80005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
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);
}
string s;
string tar = "keyence";
void Solve() {
cin >> s;
int p = 0;
while(s[p] == tar[p]) ++p;
int q = 0;
while(s[s.length() - 1 - q] == tar[tar.length() - 1 - q]) ++q;
if(p + q >= tar.length()) puts("YES");
else puts("NO");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
C - Exam and Wizard
就是先用一遍A的总和恢复出B,如果不足就是-1,然后贪心每次恢复最少可以回到原来的大小
#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 MAXN 100005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
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;
int64 A[MAXN],B[MAXN],all,C[MAXN];
multiset<int64> S;
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(A[i]);all += A[i];
}
for(int i = 1 ; i <= N ; ++i) {
read(B[i]);all -= B[i];
if(A[i] - B[i] >= 0) S.insert(A[i] - B[i]);
}
if(all < 0) {puts("-1");return;}
int cnt = 0;
while(!S.empty()) {
int64 p = *S.begin();
S.erase(S.begin());
if(all >= p) {all -= p;++cnt;}
else break;
}
out(N - cnt);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
D - Double Landscape
感觉这题so interesting 啊,还可以往高维拓展
从大到小往里面塞数,记录一下每次能用的行和列,如果这个数必须在某一行或某一列,两个都固定就乘上1,一个固定,比如行固定,就乘上能用的列数
如果这个数位置没被固定,就是乘上当前能用的行列数的乘积,减去比它大的数
为什么呢。。因为一个数能填的位置,要么和前面比它大的数都没有交集,要么前面比它大的数能填的集合是它的一个真子集
#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 MAXN 1005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
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;
bool col[MAXN * MAXN],row[MAXN * 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 Solve() {
read(N);read(M);
int a;
for(int i = 1 ; i <= N ; ++i) {
read(a);
if(row[a]) {puts("0");return;}
row[a] = 1;
}
for(int i = 1 ; i <= M ; ++i) {
read(a);
if(col[a]) {puts("0");return;}
col[a] = 1;
}
int ans = 1;
int c = 0,r = 0;
for(int i = N * M ; i >= 1 ; --i) {
int tc = c,tr = r;
if(col[i]) {tc = 1;++c;}
if(row[i]) {tr = 1;++r;}
if(col[i] || row[i]) ans = mul(ans,tc * tr);
else ans = mul(ans,tc * tr - (N * M - i));
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
E - Connecting Cities
外国人真是瞧不起中国人的数据结构水平
随手写了个线段树就过了
就是拆式子,分\(-i * D + A_i\)和\(i * D + A_i\)
然后跑prim,两个线段树取最小的就行
#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 MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
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;int64 D;
int64 A[MAXN];
struct seg_tr {
struct node {
int L,R;
int64 cov;
pair<int64,int> val[2];
}tr[MAXN * 4];
void update(int u) {
tr[u].val[1] = mp(1e16,0);
if(tr[u].L != tr[u].R) {
tr[u].val[0] = min(tr[u << 1].val[0],tr[u << 1 | 1].val[0]);
tr[u].val[1] = min(tr[u << 1].val[1],tr[u << 1 | 1].val[1]);
}
tr[u].val[1] = min(tr[u].val[1],mp(tr[u].cov + tr[u].val[0].fi,tr[u].val[0].se));
}
void build(int u,int l,int r,int on) {
tr[u].L = l;tr[u].R = r;tr[u].cov = 1e16;
if(l == r) {
tr[u].val[0] = mp(A[l] + on * l * D,l);
update(u);
return;
}
int mid = (l + r) >> 1;
build(u << 1,l,mid,on);build(u << 1 | 1,mid + 1,r,on);
update(u);
}
void Change(int u,int l,int r,int64 v) {
if(l > r) return;
if(tr[u].L == l && tr[u].R == r) {
tr[u].cov = min(tr[u].cov,v);
update(u);
return;
}
int mid = (tr[u].L + tr[u].R) >> 1;
if(r <= mid) Change(u << 1,l,r,v);
else if(l > mid) Change(u << 1 | 1,l,r,v);
else {Change(u << 1,l,mid,v);Change(u << 1 | 1,mid + 1,r,v);}
update(u);
}
void Change_pos(int u,int p) {
if(tr[u].L == tr[u].R) {
tr[u].val[0] = mp(1e16,tr[u].L);
update(u);return;
}
int mid = (tr[u].L + tr[u].R) >> 1;
if(p <= mid) Change_pos(u << 1,p);
else Change_pos(u << 1 | 1,p);
update(u);
}
}s[2];
void Solve() {
read(N);read(D);
for(int i = 1 ; i <= N ; ++i) read(A[i]);
s[0].build(1,1,N,1);
s[1].build(1,1,N,-1);
s[0].Change_pos(1,1);s[1].Change_pos(1,1);
s[0].Change(1,2,N,A[1] - D);
int cnt = N - 1;
int64 ans = 0;
while(cnt--) {
pair<int64,int> t[2];
t[0] = s[0].tr[1].val[1],t[1] = s[1].tr[1].val[1];
if(t[0] > t[1]) swap(t[0],t[1]);
ans += t[0].fi;
int u = t[0].se;
s[0].Change_pos(1,u);s[1].Change_pos(1,u);
s[1].Change(1,1,u - 1,1LL * u * D + A[u]);
s[0].Change(1,u + 1,N,-1LL * u * D + A[u]);
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
F - Paper Cutting
怎么又是计数转期望……输了……水平不行,从前遇见期望只会转计数。。。直到atc用一堆计数转期望把我吊着打
就是考虑一个左下角为\((i,j)\)的方形,当这个点作为左下角后,每切一刀都会被统计一次,为了方便我们姑且只讨论\(i > 0\)且\(j > 0\)的情况
这个矩形第一次存在的概率是
\(\frac{\binom{K}{2}}{\binom{N}{2}}\)
就是考虑选\(i,j\)(无序)我们需要它是\(\binom{N}{2}\)中\(\binom{K}{2}\)对中的一个
之后被再次算的概率是,就是,我又拿了一个,左下角为\(i,j\)的就又被算了一次
\(\frac{\binom{K}{3}}{\binom{N}{3}}\cdot \frac{1}{3}\)我需要最后一个选的点在最后,这样的概率有\(\frac{1}{3}\)
这样的点得集合有\(N - 2\)种,所以最后的期望是
\(\frac{\binom{K}{2}}{\binom{N}{2}} + \frac{\binom{K}{3}}{\binom{N}{3}} \cdot \frac{1}{3} \cdot (N - 2)\)
对于边上的点和角上的一个点也是同理的
#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 MAXN 20000005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
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 H,W,K,N;
int C[2][4],inv[4];
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(H);read(W);read(K);
N = H + W;
inv[1] = 1;inv[2] = (MOD + 1) / 2;inv[3] = (MOD + 1) / 3;
C[0][0] = C[1][0] = 1;
for(int i = 1 ; i <= 3 ; ++i) {
C[0][i] = mul(mul(C[0][i - 1],inv[i]),K - i + 1);
C[1][i] = mul(mul(C[1][i - 1],inv[i]),N - i + 1);
}
int ans = K;
int t1 = mul(K,fpow(N,MOD - 2)),t2 = mul(C[0][2],fpow(C[1][2],MOD - 2)),t3 = mul(C[0][3],fpow(C[1][3],MOD - 2));
int s = inc(t1,mul(mul(t2,inv[2]),N - 1));
update(ans,mul(s,H + W));
s = inc(t2,mul(mul(t3,inv[3]),N - 2));
update(ans,mul(s,1LL * H * W % MOD));
for(int i = N ; i >= N - K + 1; --i) {
ans = mul(ans,i);
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}