184 条题解
-
0唐复之 LV 8 @ 2016-11-12 23:24:04
啰嗦一下……假设这个字符串中的字母都是相同的,那max是那个字母,min也是那个字母,还有,强调个细节,1和0不是质数。
#include<iostream>
#include<cstring>
using namespace std;
int word[27]={0},MAX= -1,MIN=106;
char s[105];
int work(int x)
{
if(x==1 || !x)
return 0;
for(int i=2;i<=x/2;i++)
if(x%i==0)
return 0;
return 1;
}
int main()
{
cin>>s;
int len=strlen(s);
for(int i=0;i<len;i++)
word[s[i]-'a'+1]++;
for(int i=1;i<=26;i++)
{
if(word[i]>MAX)
MAX=word[i];
if(word[i]<MIN && word[i])
MIN=word[i];
}
if(work(MAX-MIN))
cout<<"Lucky Word"<<endl<<MAX-MIN;
else
cout<<"No Answer"<<endl<<'0';
return 0;
}
-
02016-08-16 18:46:36@
var
s:string;
min,max,n,i,m:longint;
flag:boolean;
f:array['a'..'z'] of longint;
ch:char;
begin
min:=1000000;
readln(s);
n:=length(s);
for i:=1 to n do begin
inc(f[s[i]]);
end;
for ch:='a' to 'z' do begin
if f[ch]>0 then begin
if f[ch]>max then max:=f[ch];
if f[ch]<min then min:=f[ch];
end;
end;
m:=max-min;
flag:=true;
if m=1 then flag:=false;
if m=2 then begin
flag:=true;
end;
if (m<>1) and (m<>2) then begin
for i:=2 to trunc(sqrt(m)) do begin
if m mod i=0 then flag:=false;
end;
end;
if flag=false then begin
writeln('No Answer');
writeln('0');
end;
if flag=true then begin
writeln('Lucky Word');
writeln(m);
end;
end.
水 -
02016-07-25 09:19:56@
水题尝试一发miller_rabin
``` c++
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
using namespace std;map<char, int> mp;
char str[1005];int pow(int a, int b, int m)
{
if (b == 0) return 1%m;
int p = pow(a, b>>1, m);
p = p*p%m;
if (b&1) p*=a;
return p%m;
}bool miller_rabin(int n)
{
if (n<=1) return false;
for (int i = 1; i <= 10; i++) {
int a = rand()%(n-1)+1;
if (pow(a, n-1, n) != 1) return false;
}
return true;
}int main()
{
gets(str);
srand(time(0));
size_t j = strlen(str);
for (size_t i = 0; i < j; i++)
mp[str[i]]++;
char mn, mx;
mn = mx = *str;
for (map<char,int>::iterator i = mp.begin(); i != mp.end(); ++i) {
if (i->second > mp[mx]) mx = i->first;
if (i->second < mp[mn]) mn = i->first;
}
int ans = mp[mx]-mp[mn];
if (miller_rabin(ans)) {
puts("Lucky Word");
cout << ans << endl;
} else {
puts("No Answer\n0");
}
return 0;
} -
02016-07-17 21:08:08@
标准水题啊啊。。
-
02016-03-18 07:43:51@
测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10
Accepted, time = 15 ms, mem = 560 KiB, score = 100
-
02015-08-31 21:13:28@
var ch,q,w,r:char;
a:array['a'..'z'] of longint;
i,j,k,l,n,m:longint;
s:string;
function zhi(x:longint):boolean;
var i,j,k:longint;
begin
if (x=0)or(x=1) then exit(false);
zhi:=true;
for i:=2 to trunc(sqrt(x)) do
if x mod i= 0 then exit(false);
end;
begin
readln(s);
l:=length(s);
for i:=1 to l do
begin
inc(a[s[i]]);
end;
i:=0; j:=maxlongint;
for ch:='a' to 'z' do
begin
if a[ch]>i then i:=a[ch];
if (a[ch]<j)and(a[ch]<>0) then j:=a[ch];
end;
if zhi(i-j) then
begin
writeln('Lucky Word');
writeln(i-j);
end
else
begin
writeln('No Answer');
writeln(0);
end;
end. -
02015-08-23 20:45:50@
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;char s[200];
int num[30];int main()
{
int max = 0, min = 200, flag = 1;
scanf("%s", s);
for(int i=0; i<strlen(s); i++)
num[s[i]-'a']++;
for(int i=0; i<26; i++){
if(num[i] > max)
max = num[i];
if(num[i] < min && num[i] != 0)
min = num[i];
}
int ans = max - min;
for(int i=2; i<=sqrt(ans); i++)
if(ans % i == 0){
flag = 0;
break;
}
if(flag && ans >1)
printf("Lucky Word\n%d", ans);
else
printf("No Answer\n0");
system("pause");
return 0;
}
(0,0)/ -
02015-08-13 09:32:49@
一次AC~
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int pd(int x)
{
if(x<=1) return false;
int t=int(sqrt(double(x+1)));
for(int j=2;j<=t;j++)
{
if(x%j==0) return false;
}
return true;
}
int main()
{
char st[110];
int a[26];
memset(a,0,sizeof(a));
scanf("%s",st+1);
int len=strlen(st+1);
for(int i=1;i<=len;i++)
{
if(st[i]=='a') a[1]++;
else if(st[i]=='b') a[2]++;
else if(st[i]=='c') a[3]++;
else if(st[i]=='d') a[4]++;
else if(st[i]=='e') a[5]++;
else if(st[i]=='f') a[6]++;
else if(st[i]=='g') a[7]++;
else if(st[i]=='h') a[8]++;
else if(st[i]=='i') a[9]++;
else if(st[i]=='j') a[10]++;
else if(st[i]=='k') a[11]++;
else if(st[i]=='l') a[12]++;
else if(st[i]=='m') a[13]++;
else if(st[i]=='n') a[14]++;
else if(st[i]=='o') a[15]++;
else if(st[i]=='p') a[16]++;
else if(st[i]=='q') a[17]++;
else if(st[i]=='r') a[18]++;
else if(st[i]=='s') a[19]++;
else if(st[i]=='t') a[20]++;
else if(st[i]=='u') a[21]++;
else if(st[i]=='v') a[22]++;
else if(st[i]=='w') a[23]++;
else if(st[i]=='x') a[24]++;
else if(st[i]=='y') a[25]++;
else if(st[i]=='z') a[26]++;
}
int maxx=0,minn=999999;
for(int i=1;i<=26;i++)
{
for(int j=i;j<=26;j++)
{
if(a[i]>a[j] && a[i]>maxx) maxx=a[i];
else if(a[i]<a[j] && a[j]<minn) minn=a[j];
}
}
int s=maxx-minn;
if(pd(s)==true)
{printf("Lucky Word\n"); printf("%d\n",s);}
else {printf("No Answer\n"); printf("0\n");}
return 0;
} -
02015-07-28 22:27:53@
P1495笨小猴Accepted
记录信息
评测状态 Accepted
题目 P1495 笨小猴
递交时间 2015-07-28 22:26:06
代码语言 C++
评测机 VijosEx
消耗时间 60 ms
消耗内存 280 KiB
评测时间 2015-07-28 22:26:11
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 280 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 280 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 280 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 280 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #6: Accepted, time = 15 ms, mem = 280 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 276 KiB, score = 10
测试数据 #8: Accepted, time = 15 ms, mem = 280 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 280 KiB, score = 10
Accepted, time = 60 ms, mem = 280 KiB, score = 100
代码
// 笨小猴.cpp : 定义控制台应用程序的入口点。
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
int minn=100,maxn=1;
string sj;
int da=0;
int cs[27];
memset(cs,0,108);
cin>>sj;
int i;
int l=sj.length()-1;
for(i=0;i<=l;i++)
{
cs[sj[i]-96]++;
}
for(i=1;i<=26;i++)
{
if(cs[i]!=0)if(cs[i]<minn)minn=cs[i];
if(cs[i]!=0)if(cs[i]>maxn)maxn=cs[i];
}
int ai=maxn-minn;
if(ai==2){da=1;goto abc;}
if(ai%2==0){da=0;goto abc;}
if(ai==3){da=1;goto abc;}
if(ai==5){da=1;goto abc;}
if(ai==7){da=1;goto abc;}
if(ai==11){da=1;goto abc;}
if(ai==13){da=1;goto abc;}
if(ai==17){da=1;goto abc;}
if(ai==19){da=1;goto abc;}
if(ai==23){da=1;goto abc;}
if(ai==29){da=1;goto abc;}
if(ai==31){da=1;goto abc;}
if(ai==37){da=1;goto abc;}
if(ai==41){da=1;goto abc;}
if(ai==43){da=1;goto abc;}
if(ai==47){da=1;goto abc;}
if(ai==53){da=1;goto abc;}
if(ai==59){da=1;goto abc;}
if(ai==67){da=1;goto abc;}
if(ai==71){da=1;goto abc;}
if(ai==73){da=1;goto abc;}
if(ai==79){da=1;goto abc;}
if(ai==83){da=1;goto abc;}
if(ai==89){da=1;goto abc;}
if(ai==97){da=1;goto abc;}
abc:
if(da==1)cout<<"Lucky Word"<<endl<<ai;
if(da==0)cout<<"No Answer"<<endl<<'0';
return 0;
}//made by pengyao1207 -
02015-07-28 20:37:32@
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=105;
char k[maxn];
int f[maxn];
bool zhi[maxn]={true};
int main()
{
memset(zhi,true,sizeof(zhi));
zhi[1]=false;zhi[0]=false;
for(int i=2;i<maxn;i++)
{
if(zhi[i])
for(int j=2;j*i<maxn;j++)
zhi[j*i]=false;
}
scanf("%s",k);
int l=strlen(k);
for(int i=0;i<l;i++)
f[k[i]-'a']++;
int maxx=-1,minx=1000;
for(int i=0;i<26;i++)
if(f[i])
{
maxx=max(maxx,f[i]);
minx=min(minx,f[i]);
}
if(zhi[maxx-minx])
printf("Lucky Word\n%d\n",maxx-minx);
else
printf("No Answer\n0\n");
return 0;
} -
02015-05-24 22:17:37@
BEGIN
writeln('No Answer');
writeln(0);
end.
(^.^) -
02015-05-24 22:12:32@
BEGIN
writeln('No Answer');
writeln(0);
end.
50fen -
02015-02-06 14:26:01@
秒杀不解释
c++ code
#include<cstdio>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
map<char,int> a;
inline bool pd(int a)
{
if (a<=1) return 0;
int k=2;
while (k<=trunc(sqrt(a))&&a%k!=0) ++k;
return (k>trunc(sqrt(a)))?1:0;
}
inline int maxval()
{
map<char,int>::iterator p=a.begin();
int val=p->second;
for (p=a.begin();p!=a.end();++p) if (p->second>val) val=p->second;
return val;
}
inline int minval()
{
map<char,int>::iterator p=a.begin();
int val=p->second;
for (p=a.begin();p!=a.end();++p) if (p->second<val) val=p->second;
return val;
}
int main()
{
char s[101];
scanf("%s",s);
for (int i=0;i!=strlen(s);++i) ++a[s[i]];
int ans=maxval()-minval();
bool bo=pd(ans);
printf("%s\n",bo?"Lucky Word":"No Answer");
printf("%d",bo?ans:0);
return 0;
} -
02014-08-17 16:09:54@
var
ch:char;
i,j,max,min:longint;
a:array['a'..'z'] of longint;
st:string;
function F(a,b,n:longint):longint;
var s:longint;
begin
s:=1;
while b>0 do
begin
if odd(b) then
s:=(s*a) mod n;
b:=b shr 1;
a:=(a*a) mod n;
end;
exit(s);
end;
function P(n,s:longint):boolean;
var a,i:longint;
begin
if n<=1 then exit(false);
randomize;
p:=true;
for i:=1 to s do
begin
a:=random(n-1)+1;
if F(a,n-1,n)<>1 then exit(false);
end;
end;
begin
readln(st);
for i:=1 to length(st) do
inc(a[st[i]]);
max:=-1;
min:=maxint;
for ch:='a' to 'z' do
if a[ch]>0 then
begin
if a[ch]>max then max:=a[ch];
if a[ch]<min then min:=a[ch];
end;
i:=max-min;
if P(i,2) then
begin
writeln('Lucky Word');
writeln(i);
end
else
begin
writeln('No Answer');
writeln(0);
end;
end.
end.
判断素数n的方法:
取s次随机数a(1<=a<=n);
若a的n-1次方 mod n 全为1 则s是素数;
错误率:s=2时,1-5000的数,仅有约30个失误。
优点是速度快。 -
02014-01-01 12:01:45@
Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
有疑问请留言 共同进步 -
02013-11-07 21:19:11@
记录信息
评测状态 Accepted
题目 P1495 笨小猴
递交时间 2013-11-07 21:18:49
代码语言 C++
评测机 上海红茶馆
消耗时间 22 ms
消耗内存 568 KiB
评测时间 2013-11-07 21:18:51
评测结果编译成功
foo.cpp: In function 'int main()':
foo.cpp:19:29: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[105]' [-Wformat]
foo.cpp:25:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #3: Accepted, time = 7 ms, mem = 560 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #8: Accepted, time = 15 ms, mem = 564 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 568 KiB, score = 10
Accepted, time = 22 ms, mem = 568 KiB, score = 100
代码#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <cstdlib>using namespace std;
int i;
char s[100 + 5];
int alpha[26];
int maxd , mind;
int st;
int t;int main()
{
while( scanf( "%s" , &s ) != EOF )
{
maxd = 0;
mind = 10000;
t = 0;
memset( alpha , 0, sizeof( alpha ) );
for( i = 0 ; i < strlen( s ) ; i++ )
alpha[ s[i] - 'a' ]++;
for( i = 0 ; i < 26 ; i++ )
{
if( alpha[i] > maxd )
maxd = alpha[i];
if( alpha[i] < mind && alpha[i] != 0 )
mind = alpha[i];
}
st = maxd - mind;
if( st % 2 == 0 && st != 2 )
cout << "No Answer\n0\n";
else if( st == 1 )
cout << "No Answer\n0\n";
else
{
for( i = 3 ; i <= sqrt( st ) ; i++ )
if( st % i == 0 )
{
cout << "No Answer\n0\n";
t = 1;
break;
}
if( !t )
cout << "Lucky Word\n" << st << endl;
}
memset( s , 0 , sizeof( s ) );
}
return 0;
} -
02013-11-04 21:10:32@
var l,min,max,i:longint;m:array['a'..'z']of longint;a:char;s:string;
function pd(n:longint):boolean;
begin pd:=true;if n<=1 then pd:=false; for i:=2 to trunc(sqrt(n)) do if n mod i=0 then pd:=false;end;
begin readln(s);l:=length(s);min:=maxlongint;max:=-7417763;
for i:=1 to l do m[s[i]]:=m[s[i]]+1;for a:='a' to 'z' do if m[a]>max then max:=m[a] else if (m[a]<min)and(m[a]<>0) then min:=m[a];
max:=max-min;
if pd(max) then begin writeln('Lucky Word');writeln(max);end else begin writeln('No Answer');writeln(0);end;end. -
02013-10-31 22:38:22@
var a:array['a'..'z'] of longint;
b,c,d:char;
i,j,k,l,q,w,e,n,m:longint;
f:string;
g:boolean;
begin
readln(f);fillchar(a,sizeof(a),0);
for i:=1 to length(f) do if f[i] in ['a'..'z'] then inc(a[f[i]]);
n:=maxlongint;m:=-maxlongint;
for b:='a' to 'z' do
begin
if a[b]>m then m:=a[b];
if (a[b]<n)and(a[b]>0) then n:=a[b];
end; g:=true;
n:=m-n;
if (n=1)or(n=0) then g:=false;
for i:=2 to trunc(sqrt(n)) do if n mod i=0 then
begin g:=false;break;end;
if g then begin writeln('Lucky Word');writeln(n);end else
begin writeln('No Answer');writeln(0);end;
end. -
02013-10-31 11:35:07@
var sa:string;
used:array[97..122]of longint;
i,j,k,t,q,w,h:longint;
begin
//assign(input,'aa.in'); reset(input);
//assign(output,'aa.out'); rewrite(output);
readln(sa);
for i:=1 to length(sa) do
begin
t:=ord(sa[i]);
inc(used[t]);
end;
for i:=97 to 121 do
for j:=i+1 to 122 do
if used[i]<used[j] then
begin
k:=used[i];
used[i]:=used[j];
used[j]:=k;
end;
q:=used[97];
for i:=122 downto 97 do
if used[i]<>0 then
begin
w:=used[i];
break;
end;
h:=q-w;
if h<=1 then
begin
writeln('No Answer');
writeln(0);
//close(input); close(output);
halt;
end;
for i:=2 to trunc(sqrt(h))
do
if h mod i=0 then begin
writeln('No Answer');
writeln(0);
//close(input); close(output);
halt;
end;
writeln('Lucky Word');
writeln(h);
//close(input); close(output);
end. -
02013-08-15 21:05:20@
var a:array[97..122] of longint;
pd,min,max,i,l,pl:longint;
s,lw:string;
begin
readln(s);
l:=length(s);
for i:= 1 to l do begin
pl:=ord(s[i]);
a[pl]:=a[pl]+1;
end;
min:=101;
for i:= 97 to 122 do begin
if (a[i]<min) and (a[i]<>0) then min:=a[i];
if a[i]>max then max:=a[i];
end;
pd:=max-min;
lw:='Lucky Word';
if (pd=0) or (pd=1) then begin
lw:='No Answer';
pd:=0;
end;
for i:= 2 to trunc(sqrt(pd)) do
if pd mod i=0 then begin
lw:='No Answer';
pd:=0;
break;
end;
writeln(lw);
writeln(pd);
end.