Codeforces Round #253 (Div. 2)

来源:互联网 发布:windows10视频剪辑软件 编辑:程序博客网 时间:2024/06/05 23:54

A. Anton and Letters

地址链接:点击打开链接

思路:找出字符串中不同的小写字母,直接模拟即可


#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>using namespace std;int main(){    char s[2000];    char a[2000] = {'\0'};    int cnt = 0;    gets(s);    for(int i = 0; s[i] != '\0'; i++)    {        if(s[i] >= 'a' && s[i] <= 'z')        {            int flag = 1;            for(int j = 0; a[j] != '\0'; j++)            {                if(s[i] == a[j])                {                    flag = 0;                    break;                }            }            if(flag == 1)            {                a[cnt++] = s[i];            }        }    }    cout << cnt << endl;    return 0;}

B. Kolya and Tandem Repeat

地址链接:点击打开链接

思路:可以在字符串后添加最多K个字符,找出最大的重复子串,即s[i+len] = s[i]。可以从最长的子串长度来进行枚举,由于最后添加进去的字符可以任意选择,所以只需考虑原本长度内的字符即可,另外添加长度可能会大于字符串原本的长度


#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>#include <string>using namespace std;int main(){    string s;    int k;    cin >> s;    cin >> k;    int l = s.length();    int ans = 0;    for(int i = (k + l) / 2; i >= 1; i--)    {        for(int j = 0; j + i * 2 - 1 < k + l; j++)        {            for(int k = i + j; k < j + i * 2 && k < l; k++)            {                if(s[k] != s[k - i])                    goto hehe;            }            ans = max(ans, i);            hehe: ;        }    }    cout << ans * 2 << endl;    return 0;}


D. Andrey and Problem

题目链接:点击打开链接

思路:给主人公一些事件的成功概率,他想恰好只成功一件,问他要选择哪些事件去做,才能让实现的概率最大。

先看只做一件事成功1件的最大概率,再看2件中,3件中,…… 一旦概率没上次高就跳出,就是不知道怎么证明。。。


#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>#include <string>using namespace std;double sum = 0 , ans = 0;double a[300];int n;int main(){    scanf("%d", &n);    double ans = 0, ss = 0;    for(int i = 0; i < n; i++)        scanf("%lf", &a[i]);    sort(a, a + n);    ans = a[n - 1];    ss = 1.0 - ans;    for(int i = n - 2; i >= 0; i--)    {        sum = ans * (1 - a[i]) + ss * a[i];        if(sum > ans)            ans = sum;        else            break;        ss *= (1 - a[i]);    }    printf("%.12lf\n", ans);    return 0;}



0 0
原创粉丝点击