Test48提高组考试总结
Claire0630 · · 题解
Test48提高组考试总结
Data
80 = 40 + 0 + 30 + 10
Preface
Manba Out! 坠大机了孩子们 想我了吗?
好吧好吧,我没辙了 T1题读错了 T2“Ctrl + Z”按多了(实际上是自己唐了,忘记初始化了) T3复杂度就多了个log就直接少了50pts T4的暴力又没读题!!!写坠机了 好吧,我没辙了
Statements
A、仓鼠的石子游戏
时间限制: 1 s 空间限制: 512 MB
题目描述
仓鼠和兔子被禁止玩电脑,无聊的他们跑到一块空地上,空地上有许多小石子。兔子捡了很多石子,然后将石子摆成
输入描述
第一行输入一个正整数
每组测试案例的第一行输入一个
输出描述
对于每组测试案例,如果兔子赢了,输出 "rabbit" (不含引号);如果仓鼠赢了,输出 "hamster" (不含引号)。
输入样例
4
1
3
1
2
2
1 3
3
999 1000 1000000000
输出样例
hamster
rabbit
rabbit
hamster
说明
对于第一组案例:只有 1 圈石子,并且石圈的大小为 3。兔子先手,随便找了一个石子染成红色,接下来仓鼠后手找一个未染色的石子染成蓝色,此时结果如下图所示。如果兔子将最后一个石子染成红色,这将导致相邻石子同色,根据规则,他输掉了比赛,所以仓鼠获得了最终的胜利。
对于第二组案例:只有 1 圈石子,并且石圈的大小为 1。兔子先手,将唯一的一个石子染成了红色,接下来由于没有未着色的石子,所以仓鼠由于无法操作而输掉了比赛,兔子取得了最终的胜利。
对于第三组案例:有两个石圈,大小分别为 1, 3,兔子首先将大小为 1 的石圈中唯一一个石子染成了红色,接下来仓鼠由于类似第一组案例中的原因输掉比赛,兔子取得了最终的胜利。
Solution
好吧好吧,是我太烫了
我题读错了好吧
这道题是
我们只需要关注长度为
注意到此游戏先手必输
就这样,我没辙了
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
template <typename T> inline void read(T &x){
x = 0;
LL f = 1;
char c = getchar();
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
template <typename T> inline void print(T x){
if(x < 0) x = -x,putchar('-');
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
inline void sprint(const string s){
for(auto x : s) putchar(x);
return;
}
const int N = 1e5 + 11;
LL t;
int main(){
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
read(t);
while(t --){
LL n,cnt = 0;
read(n);
for(LL i=1;i<=n;i++){
LL x;
read(x);
if(x == 1){
cnt ++;
continue;
}
}
if(cnt % 2 == 1) sprint("rabbit");
else sprint("hamster");
putchar('\n');
}
return 0;
}
B、乘法师
时间限制: 1 s 空间限制: 512 MB
题目描述
给定一个长为
输入描述
第一行一个正整数
输出描述
对于每组数据,输出一行一个整数,表示答案。
输入样例
1
3 7
2 3 4
输出样例
2
备注
对于前 20% 的数据,
对于前 50% 的数据,
对于所有数据,
Solution
这道题不就是滑动窗口+双指针吗,好吧好吧
滑动窗口卡住刚刚好大于等于
我TM第一遍双指针写错了
Ctrl+Z撤回了几步就把初始化给忘了
我没辙了
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
template <typename T> inline void read(T &x){
x = 0;
LL f = 1;
char c = getchar();
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
template <typename T> inline void print(T x){
if(x < 0) x = -x,putchar('-');
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
inline void sprint(const string s){
for(auto x : s) putchar(x);
return;
}
const int N = 1e5 + 11;
LL n,v,t,cnt;
LL a[N];
vector<LL> gp;
int main(){
// freopen("ex_b.in","r",stdin);
// freopen("b.out","w",stdout);
read(t);
while(t --){
cnt = 0;
read(n);read(v);
for(LL i=1;i<=n;i++) read(a[i]);
if(v == 0){
print(n * (n + 1) / 2);
putchar('\n');
continue;
}
gp.clear();
gp.emplace_back(0);
for(LL i=1;i<=n;i++){
if(a[i] == 0) gp.emplace_back(i);
}
gp.emplace_back(n + 1);
LL tot = a[1],j = 1;
for(int i=1;i<=n;){
if(a[i] == 0){
tot = 1;
i ++;
j = i - 1;
continue;
}
while(j <= n && tot < v){
j ++;
if(a[j] == 0) break;
tot *= a[j];
if(tot >= v) break;
}
if(tot < v){
tot = 1;
i = j;
continue;
}
LL pos = lower_bound(gp.begin(),gp.end(),j) - gp.begin();
cnt += gp[pos] - j;
tot /= a[i];
i ++;
}
print(cnt);
putchar('\n');
}
return 0;
}
/*
1
10 31
1 2 3 5 6 2 2 0 1 5
1
3 7
2 3 4
*/
C、乃爱与城市拥挤程度
题目描述
乃爱天下第一可爱!乃爱居住的国家有
假设
- 1 号城市到 1 号城市经过了 1 号城市。
- 2 号城市到 1 号城市经过了 1 号、2 号城市。
- 3 号城市到 1 号城市经过了 1 号、2 号、3 号城市。
- 4 号城市到 1 号城市经过了 1 号、2 号、4 号城市。
- 5 号城市到 1 号城市经过了 1 号、2 号、5 号城市。
所以 1 号城市的拥挤程度是 5,2 号城市的拥挤程度是 4,3 号、4 号、5 号城市的拥挤程度都是 1。
现在小
输入描述
第一行是两个正整数
接下来
输出描述
输出两行。第一行
第二行
Solution
我的天,这道题直接暴力
但我的暴力是
暴力确实很简单,但我的暴力还是太吃操作了
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 SLL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
template <typename T> inline void read(T &x){
x = 0;
LL f = 1;
char c = getchar();
for(; !isdigit(c); c=getchar()) if(c == '-') f = -1;
for(; isdigit(c); c=getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
template <typename T> inline void print(T x){
if(x < 0) x = -x,putchar('-');
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
inline void sprint(const string s){
for(auto x : s) putchar(x);
return;
}
const int N = 1e5 + 11,M = 35;
const LL Big = 1e9 + 7;
LL n,k;
vector<LL> g[N];
LL ct[N],c[N],ans[N],dep[N],f[N][M];
void dfs(LL u,LL fa){
for(auto x : g[u]){
if(x == fa) continue;
dep[x] = dep[u] + 1;
f[x][0] = u;
for(LL i=1;i<=20;i++) f[x][i] = f[f[x][i - 1]][i - 1];
dfs(x,u);
}
}
LL lca(LL x,LL y,LL &cnt){
if(dep[x] < dep[y]) swap(x,y);
LL stp = dep[x] - dep[y];
for(LL i=20;i>=0;i--){
if(stp >= (1 << i)){
stp -= (1 << i);
cnt += (1 << i);
x = f[x][i];
}
}
if(x == y) return x;
for(LL i=20;i>=0;i--){
if(f[x][i] != f[y][i]){
x = f[x][i];
y = f[y][i];
cnt += (1 << i) * 2;
}
}
cnt += 2;
return f[x][0];
}
void dfs2(LL u,LL fa){
for(auto x : g[u]){
if(x == fa) continue;
dfs2(x,u);
c[u] += c[x];
}
}
int main(){
// freopen("c.in","r",stdin);
// freopen("c.out","w",stdout);
read(n);read(k);
for(LL i=1;i<n;i++){
LL st,dst;
read(st);read(dst);
g[st].emplace_back(dst);
g[dst].emplace_back(st);
}
dfs(1,0);
for(LL i=1;i<=n;i++){
for(LL j=1;j<=n;j++) c[j] = 0;
LL tot = 1;
vector<LL> v;
v.clear();
for(LL j=1;j<=n;j++){
LL pth = 0;
LL rt = lca(i,j,pth);
if(pth <= k){
v.emplace_back(j);
c[i] ++;
c[j] ++;
c[rt] --;
c[f[rt][0]] --;
}
}
dfs2(1,0);
for(auto x : v) tot = (tot % Big * c[x] % Big) % Big;
ct[i] = v.size(),ans[i] = tot % Big;
}
for(LL i=1;i<=n;i++){
print(ct[i]);
putchar(' ');
}
putchar('\n');
for(LL i=1;i<=n;i++){
print(ans[i]);
putchar(' ');
}
return 0;
}
我们其实发现这道题就是换根dp,然后我们就做完了
关于我TM差点把换根dp给忘了,所以变量名起得比我的**还长这回事,(这不重要)
我们先以1为根节点,先算出以1为根的情况
我们设