这一场真*爆0场,被自己的理解坑了,把那个子序列以为是字串了,原地爆炸,好亏好亏,第二题是一道博弈论,然鹅我就只有一种情况没想出来,还是挂了真滴难受
A.牛牛的独特子序列(二分)
bool check(string x,int n) {//n表示的是当前期望取的子序列的长度
int tlen[3]={0};
int len = x.length();
for(int i = 0;i < len; ++i) {
if(tlen[0] < n && x[i]== 'a') {//先取a
tlen[0]++;
}
else if(tlen[0] == n && tlen[1] < n && x[i] == 'b') {//满足先取a,再取b
tlen[1]++;
}
else if(tlen[1] == n && tlen[2] < n && x[i] == 'c') {//满足先取b,再取c
tlen[2]++;
}
}
if(tlen[0] == tlen[1] && tlen[1] == tlen[2] && tlen[0] == n)//如果满足条件
return true;
return false;
}
int Maximumlength(string x) {
// write code here
int ans = 0;
int len = x.length();
int l = -1, r = len/3;
while(l + 1 < r) {//二分(我的二分板子)
int mid =l + r >> 1;
if(check(x,mid)){
l = mid;
}
else
r = mid;
}
return l * 3;
}
这道题因为把子序列以为成了字串,差点让我觉得题目的数据有问题(QAQ),看来还是自己太菜了
分贝壳游戏
int Gameresults(int n, int p, int q) {
// write code here
if(p >= n || p > q)
return 1;
if(p < q)
return -1;
if(n%(p+1)==0)
return -1;
else
return 1;
}
经过直径的点
树形DP,(不会)