Codeforces Round #253 (Div. 2)

A. Anton and Letters
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.

Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.

Input

The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.

Output

Print a single number — the number of distinct letters in Anton's set.

Sample test(s)
input
{a, b, c}
output
3
input
{b, a, b, a}
output
2
input
{}
output
0


//15 ms	 0 KB
#include<stdio.h>
#include<string.h>
char s[1007];
int z[30];
int main()
{
    gets(s);
    int len=strlen(s),count=0;
    memset(z,0,sizeof(z));
    for(int i=0;i<len;i++)
    {
        if(s[i]>='a'&&s[i]<='z')
            z[s[i]-'a'+1]++;
    }
    for(int i=1;i<=26;i++)
        if(z[i])count++;
    printf("%d\n",count);
}

B. Kolya and Tandem Repeat
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?

See notes for definition of a tandem repeat.

Input

The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.

Output

Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.

Sample test(s)
input
aaba
2
output
6
input
aaabbbb
2
output
6
input
abracadabra
10
output
20
Note

A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.

In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.

//15 ms	 0 KB
#include<stdio.h>
#include<string.h>
char s[1007];
int main()
{
    int n;
    scanf("%s",s);
    scanf("%d",&n);
    int len=strlen(s),maxlen=0;
    if(n>=len){printf("%d\n",(n+len)/2*2);return 0;}//假设加入的长度大于等于原串长度
    for(int i=1;i<len;i++)//求在加入之前原串符合条件的最长长度
        for(int j=0;j<len;j++)
        {
            int flag=0;
            for(int k=j,num=1;num<=i;num++,k++)
                if(s[k]!=s[k+i]){flag=1;break;}
            if(!flag){maxlen=i;break;}
        }
    int maxx=n+len;
    int a=maxx/2;
    for(int i=a;i>=0;i--)//枚举加入之后的最长长度
    {
        int flag=0;
        for(int j=len-1,num=1;num<=(i-n);j--,num++)
            if(s[j]!=s[len-i-num]){flag=1;break;}
        if(!flag)
        {
            if(i>maxlen)printf("%d\n",i*2);
            else printf("%d\n",maxlen*2);
            break;
        }
    }
}

D. Andrey and Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.

Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi(0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.

Output

Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.

Sample test(s)
input
4
0.1 0.2 0.3 0.8
output
0.800000000000
input
2
0.1 0.2
output
0.260000000000
Note

In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.

In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.

题意是说给你n个数,每一个数代表为1的概率是多少,让你从中选择一个或者多个数使其概率为1的最大。

将n个数从大到小排序,假设选择一个要使概率最大,则肯定选择第一个数。

假设选择两个使其概率最大,则肯定选择前两个数,选择三个。则选择前三个数,以此推类。

仅仅要求出前一个到前n个全部情况。然后取最大即是所求。

//31 ms	 0 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
double s[107];
int cmp(double a,double b){return a>b;}
int main()
{
    int n;
    double maxx=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lf",&s[i]);
    sort(s,s+n,cmp);
    for(int i=1;i<=n;i++)
    {
        double ans=0;
        for(int j=0;j<i;j++)
        {
            double a=s[j];
            for(int k=0;k<i;k++)
                if(k!=j)a*=1-s[k];
            ans+=a;
        }
        maxx=max(maxx,ans);
    }
    printf("%.12lf\n",maxx);
}


内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值