五一期间,怎么能闲着,好久都没打大型个人赛了,来一场找找感觉
总的难度感觉还可以,最终六题收场,海星
A Red Rover
思路:其实这题可能在刚开场的时候,给人一种签到题的感觉,由于排在第一个,大家一起拼命过题,导致ac数直线上升,然而,就我个人而言,刚看到这题的时候确实没什么太多思路,只是最终看到过题数较多重回来思考才成功在终场前过掉了这一题
然后,现在整理来看,思路也是很清晰的,由于串长只有100,果断O(n^2)暴力,对于每一个子串,贪心取第一个,一开始还担心这种贪心策略会出问题,然后来细思发现必定没什么问题,第一个一定为最长值,再考虑一下边界,于是顺利ac
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
string s,ns,temp;
int main()
{
//freopen("in.txt","r",stdin);
cin >> s;
int n = s.size();
int re = n;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int num = 0;
int len = j-i+1;
ns = s.substr(i,len);
for(int pos=0;pos+len<=n;pos++)
{
temp = s.substr(pos,len);
if(temp == ns)
{
num++;
pos+= len - 1;
}
}
int tempre = n - num * (len - 1) + len;
if(tempre < re)
{
re = tempre;
//cout << ns << endl;
}
}
}
cout << re << endl;
return 0;
}
B 杨老师的游戏
思路:这才是本次比赛真正意义上的签到题,就是强行暴力枚举,首先生成9位数,共有9!种,再分别插入乘号和加号,计算,复杂度为O(9!*^3)=O(2.65*10^8)感觉海星,直接上代码,成功签到
这里,普及一个生成子串的好方法
do
{
……
}while(next_permutation(a,a+9));
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 1e5+10;
int a[9] = {1,2,3,4,5,6,7,8,9};
int main()
{
int n;
scanf("%d",&n);