新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)

五一期间,怎么能闲着,好久都没打大型个人赛了,来一场找找感觉

总的难度感觉还可以,最终六题收场,海星

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);
  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值