//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);
}
//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;
}
}
}
题意是说给你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);
}