Educational Codeforces Round 88 (Rated for Div. 2)

题目链接

A.Berland Poker

如果每个人拿的牌多于joker的数量,就把joker全给一个人使其获胜得最高分。使胜者所拿的牌全为joker,剩下的joker平均分给其他人。

//#define LOCAL
#include 
using namespace std;
#define DBG printf("%d %s\n",__LINE__,__FUNCTION__)
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define LF putchar('\n')
#define SP putchar(' ')
#define eb emplace_back
#define mk make_pair
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-6
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long
 
template<typename T> 
void read(T &x) {x = 0;char ch = getchar();LL f = 1;while(!isdigit(ch)){if(ch == '-')f *= -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48; ch = getchar();}x *= f;}
template<typename T, typename... Args> 
void read(T &first, Args& ... args) {read(first);read(args...);}
template<typename T>
void write(T arg) {T x = arg;if(x < 0) {putchar('-'); x =- x;}if(x > 9) {write(x / 10);}putchar(x % 10 + '0');}
template<typename T, typename ... Ts>
void write(T arg, Ts ... args) {write(arg);if(sizeof...(args) != 0) {putchar(' ');write(args ...);}}
 
const LL MOD = 1e9 + 7;
const int MAXN = 0;
 
int n, m, k, T;
 
int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    cin >> T;
    while(T--) {
    	cin >> n >> m >> k;
    	if(m > n / k) {
    		int p = n / k;
    		cout << p - (((m - p) + (k - 2)) / (k - 1))  << endl;
    	} else {
    		cout << m << endl;
    	}
    }
    return 0;
}

B.New Theatre Square

通过价值判断 1 × 1 1 \times1 1×1的方格是否可以替代 1 × 2 1 \times 2 1×2的方格

//#define LOCAL
#include 
using namespace std;
#define DBG printf("%d %s\n",__LINE__,__FUNCTION__)
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define LF putchar('\n')
#define SP putchar(' ')
#define eb emplace_back
#define mk make_pair
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-6
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

template<typename T> 
void read(T &x) {x = 0;char ch = getchar();LL f = 1;while(!isdigit(ch)){if(ch == '-')f *= -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48; ch = getchar();}x *= f;}
template<typename T, typename... Args> 
void read(T &first, Args& ... args) {read(first);read(args...);}
template<typename T>
void write(T arg) {T x = arg;if(x < 0) {putchar('-'); x =- x;}if(x > 9) {write(x / 10);}putchar(x % 10 + '0');}
template<typename T, typename ... Ts>
void write(T arg, Ts ... args) {write(arg);if(sizeof...(args) != 0) {putchar(' ');write(args ...);}}

const LL MOD = 1e9 + 7;
const int MAXN = 105;

int T, n, m, x, y;
char s[MAXN][1005];

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    read(T);
    while(T--) {
    	read(n, m, x, y);
    	int one = 0, two = 0;
    	for(ri i = 1; i <= n; ++i) {
    		scanf("%s", s[i] + 1);
    		for(ri j = 1; j <= m; ++j) {
    			if(s[i][j] == '.' && s[i][j+1] == '.' && j + 1 <= m) {
    				s[i][j] = s[i][j+1] = '*';
    				++two;
    				continue;
    			}
    			if(s[i][j] == '.') {
    				++one;
    			}
    		}
    	}
    	if(x * 2 < y) {
    		write((two * 2 + one) * x);
    	} else {
    		write(two * y + one * x);
    	}
    	LF;
    }
    return 0;
}

C.Mixing Water

设倒 x x x杯热水, y y y杯冷水,由于交替进行,所以 x x x y y y的关系为 x = y x = y x=y x = y + 1 x=y+1 x=y+1,若为前者,则温度为 h + c 2 \frac{h+c}{2} 2h+c,若为后者, y y y代入 x x x,温度为 x × ( c + h ) − c 2 × x − 1 \frac{x\times(c+h)-c}{2\times x-1} 2×x1x×(c+h)c,解方程,求 x x x上取整, x x x下取整和第一种情况与 t t t差值最小

//#define LOCAL
#include 
using namespace std;
#define DBG printf("%d %s\n",__LINE__,__FUNCTION__)
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define LF putchar('\n')
#define SP putchar(' ')
#define eb emplace_back
#define mk make_pair
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-6
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

template<typename T> 
void read(T &x) {x = 0;char ch = getchar();LL f = 1;while(!isdigit(ch)){if(ch == '-')f *= -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48; ch = getchar();}x *= f;}
template<typename T, typename... Args> 
void read(T &first, Args& ... args) {read(first);read(args...);}
template<typename T>
void write(T arg) {T x = arg;if(x < 0) {putchar('-'); x =- x;}if(x > 9) {write(x / 10);}putchar(x % 10 + '0');}
template<typename T, typename ... Ts>
void write(T arg, Ts ... args) {write(arg);if(sizeof...(args) != 0) {putchar(' ');write(args ...);}}

const LL MOD = 1e9 + 7;
const int MAXN = 0;

int T;
double h, c, t;

double cal(LL x, LL y) {
	return ((x * h + y * c) * 1.0) / ((x + y) * 1.0);
}

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    cin >> T;
    while(T--) {
    	cin >> h >> c >> t;
    	double x = (c - t) / (c + h - 2 * t);
    	double p = 1e18;
    	LL ans = INF;
    	if(x > 0) {
    		if(fabs(cal(floor(x), floor(x) - 1) - t) > fabs(cal(ceil(x), ceil(x) - 1) - t)) {
    			p = fabs(cal(ceil(x), ceil(x) - 1) - t);
    			ans = 2 * ceil(x) - 1;
    		} else {
    			p = fabs(cal(floor(x), floor(x) - 1) - t);
    			ans = 2 * floor(x) - 1; 
    		}
    	}
    	if(fabs((h + c) / 2 - t) < p) {
    		ans = 2;
    	}
    	write(ans), LF;
    }
    return 0;
}

D.Yet Another Yet Another Task

枚举区间最大值,枚举值为 i i i时,通过大于 i i i的数将整个区间分为若干个小区间,对于每一个小区间求最大连续子段和 d p dp dp,求出来的 d p dp dp如果不包含 i i i,则 d p − i dp-i dpi要小于 ( d p − (dp- (dp区间 m a x ) max) max),此答案一定劣于枚举值为此区间 m a x max max时的答案。

//#define LOCAL
#include 
using namespace std;
#define DBG printf("%d %s\n",__LINE__,__FUNCTION__)
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define LF putchar('\n')
#define SP putchar(' ')
#define eb emplace_back
#define mk make_pair
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-6
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

template<typename T> 
void read(T &x) {x = 0;char ch = getchar();LL f = 1;while(!isdigit(ch)){if(ch == '-')f *= -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48; ch = getchar();}x *= f;}
template<typename T, typename... Args> 
void read(T &first, Args& ... args) {read(first);read(args...);}
template<typename T>
void write(T arg) {T x = arg;if(x < 0) {putchar('-'); x =- x;}if(x > 9) {write(x / 10);}putchar(x % 10 + '0');}
template<typename T, typename ... Ts>
void write(T arg, Ts ... args) {write(arg);if(sizeof...(args) != 0) {putchar(' ');write(args ...);}}

const LL MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;

int n, a[MAXN];

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    read(n);
    for(ri i = 1; i <= n; ++i) {
    	read(a[i]);
    }
    int ans = 0;
    for(ri i = 0; i <= 30; ++i) {
    	int dp = 0, res = 0;
    	for(ri j = 1; j <= n; ++j) {
    		if(a[j] > i) {
    			dp = 0;
    		} else {
    			dp = max(dp + a[j], 0);
    		}
    		res = max(dp, res);
    	}
    	ans = max(ans, res - i);
    }
    write(ans), LF;
    return 0;
}

E.Modular Stability

数学题,结论是 a 1 a_1 a1后面的数都为 a 1 a_1 a1的倍数时,此序列 s t a b l e stable stable
证明: a 1 a_1 a1为序列中最小的数,无论它位置在哪, x % a 1 x\%a_1 x%a1 % \% %任何数结果不变。设 x % a 1 = r x\%a_1=r x%a1=r,则 x = k a 1 + r x=ka_1+r x=ka1+r x x x模任何一个 a 1 a_1 a1的倍数形式不变,所以符合结论的任何排列都满足最终结果不变。不符合结论的序列中必存在 p a 1 + t pa_1+t pa1+t这样一个不为 a 1 a_1 a1倍数的数,则必存在一种排列 p a 1 + t , a 1 pa_1+t,a_1 pa1+t,a1,可以证明这种排列与 a 1 a_1 a1开头的序列结果不同。
所以可以枚举 a 1 a_1 a1 n n n以内 a 1 a_1 a1的倍数有 p = n a 1 − 1 p=\frac{n}{a_1}-1 p=a1n1个,取其中 k − 1 k-1 k1个,有 C p k − 1 C_{p}^{k-1} Cpk1

//#define LOCAL
#include 
using namespace std;
#define DBG printf("%d %s\n",__LINE__,__FUNCTION__)
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define LF putchar('\n')
#define SP putchar(' ')
#define eb emplace_back
#define mk make_pair
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-6
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

template<typename T> 
void read(T &x) {x = 0;char ch = getchar();LL f = 1;while(!isdigit(ch)){if(ch == '-')f *= -1;ch = getchar();}while(isdigit(ch)){x = x * 10 + ch - 48; ch = getchar();}x *= f;}
template<typename T, typename... Args> 
void read(T &first, Args& ... args) {read(first);read(args...);}
template<typename T>
void write(T arg) {T x = arg;if(x < 0) {putchar('-'); x =- x;}if(x > 9) {write(x / 10);}putchar(x % 10 + '0');}
template<typename T, typename ... Ts>
void write(T arg, Ts ... args) {write(arg);if(sizeof...(args) != 0) {putchar(' ');write(args ...);}}

const LL MOD = 998244353;
const int MAXN = 5e5 + 50;

LL n, k, fac[MAXN], inv[MAXN];

LL qpow(LL a, LL p) {
	LL sum = 1;
	while(p) {
		if(p & 1) {
			sum = sum * a % MOD;
		}
		a = a * a % MOD;
		p >>= 1;
	}
	return sum;
}

LL get_inv(LL k) {
	return qpow(k, MOD - 2);
}

void pre() {
	fac[0] = 1;
	for(ri i = 1; i <= n; ++i) {
		fac[i] = fac[i-1] * i % MOD;
		inv[i] = get_inv(fac[i]);
	}
}

LL C(LL n, LL m) {
	if(m > n) {
		return 0;
	} else {
		return fac[n] * get_inv(fac[n-m] * fac[m] % MOD) % MOD;
	}
}

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    read(n, k);
    pre();
    LL ans = 0;
    for(ri i = 1; i <= n; ++i) {
    	LL p = n / i - 1;
    	ans = (ans + C(p, k - 1)) % MOD;
    }
    write(ans), LF;
    return 0;
}

你可能感兴趣的:(比赛)