184 条题解
-
0wollw1996 LV 4 @ 2009-09-20 09:00:52
program p1128;
var n,k,i,sum:longint; a,b:array[1..10000]of longint;
function sushu(l:longint):boolean;
var i:longint;
begin
sushu:=true;
for i:=2 to trunc(sqrt(l)) do
if l mod i=0 then begin sushu:=false; break end;
end;
procedure find(x,y:longint);
var i,s:longint;
begin
if x>k then begin
s:=0;
for i:=1 to k do
s:=s+b[i];
if sushu(s)=true then sum:=sum+1; exit;
end;
for i:=y to n do
begin
b[x]:=a[i];
find(x+1,i+1);
end;
end;
begin
readln(n,k);
for i:=1 to n do
read(a[i]);
find(1,1);
writeln(sum);
end. -
02009-09-17 19:57:21@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
02009-09-15 18:30:51@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms判断素数可以用暴力,也可以用米勒拉宾素数随机测试..怎么搞都可以过~
-
02009-09-03 19:13:21@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms -
02009-09-02 17:52:14@
Orz教主!!!!!!!!!!!!!!!!!!!!
dfs(sum+a[j],count+1,j+1);
dfs(sum,count,j+1); -
02009-08-29 14:19:40@
请仔细看这里-->你被忽悠啦,笨蛋!
-
02009-08-28 13:37:41@
判素数用最死的办法(mod),筛法内存会爆,不会超时!
-
02009-08-19 16:32:46@
var
i,n,t,v,k,x:longint;a,b:array[1..20]of integer;
{{{procedure pdout;
var b,c,d:integer;
f:boolean;
begin
c:=0;f:=true;
for b:=1 to k do
c:= a +c;
for d:=2 to round(sqrt(c)) do
if c mod d =0 then f:=false;
if f then x:=x+1;
end;}}判断是否是素数,如果是,x+1。procedure sort(t,j:integer);
var
i:integer;
begin
if t>k{选出k个数}
then pdoutelse begin
for i:=j{j以前是已经搜过的数} to n do
begin
a[t]:=b[i];{记录排列方法}
sort(t+1,i+1);
end
end
end;begin
x:=0;
read(n,k);
for i:=1 to n do
read(b[i]);sort(1,1);
write(x);
end. -
02009-08-19 15:14:46@
var
a:array[0..20]of longint;
n,k,sum:integer;
i,j,l:longint;procedure doit(x,y,z:integer);
var i,j,l:integer;
v:boolean;begin
if x=k then
begin
v:=true;
for j:=2 to round(sqrt(y)) do
if y mod j=0 then
begin
v:=false;
break
end;
if v then inc(sum);
end;
for i:=z+1 to n do
begin
y:=y+a[i];
doit(x+1,y,i);
y:=y-a[i];
end;
end;begin
readln(n,k);
for i:=1 to n do
read(a[i]);
doit(0,0,0);
writeln(sum)
end. -
02009-08-19 11:08:27@
请仔细看这里-->你被忽悠啦,笨蛋!
-
02009-08-17 11:59:56@
var i,n,k,s,w:longint;
a,b:array[0..20] of longint;
flag:set of 0..20;
function zs(k:longint):boolean;
var t:longint;
begin
zs:=true;
for t:=2 to round(sqrt(k)) do
if k mod t=0 then
begin
zs:=false;
exit;
end;
end;
procedure find(m:integer);
var j:integer;
begin
if (m>k) and zs(s) then begin w:=w+1; exit; end;
if m>k then exit;
for j:=1 to n do
if not(j in flag) and (j>b[m-1]) then
begin
b[m]:=j;
s:=s+a[j];
flag:=flag+[j];
find(m+1);
s:=s-a[j];
flag:=flag-[j];
end;
end;
begin
readln(n,k);
for i:=1 to n do
read(a[i]);
find(1);
writeln(w);
end. -
02009-08-16 17:37:09@
program ex1;
var p:array[1..1229]of integer;
x:array[1..20]of longint;
a:array[0..20]of integer;
sum,total:longint;
i:longint;
n,k,j:integer;
function sushuo(i:longint):boolean;
var j:longint;
l:boolean;
begin
j:=2;
while i mod j0 do j:=j+1;
if j>sqrt(i) then sushuo:=true
else sushuo:=false;
end;
function tj(n,k:integer):longint;
var total:longint;
begin
total:=0;
for i:=0 to k do a[i]:=i;
while a[0]=0 do
begin
sum:=0;
for i:=1 to k do sum:=sum+x[a[i]];
if sushuo(sum) then total:=total+1;
j:=k;
while a[j]=n+j-k do j:=j-1;
a[j]:=a[j]+1;
for i:=j+1 to k do a[i]:=a+1;
end;
tj:=total;
end;
begin
read(n,k);
for i:=1 to n do read(x[i]);
total:=tj(n,k);
writeln(total);
end. -
02009-08-13 12:08:28@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms
幸好手头有数据可以测一下,不然就被骗了。。不是求有几个素数 -
02009-08-11 21:59:23@
基础题。。。细心
Program P1128;
var a:array[0..50] of int64;
b:array[0..50] of boolean;
i,j,n,m,tot:longint;function check(t:int64):boolean;
var i:longint;
begin
check:=true;
if tt) then
begin
b[i]:=false;
search(i,s+1,k+a[i]);
b[i]:=true;
end;
end;Begin
fillchar(b,sizeof(b),true);
tot:=0;
readln(n,m);
for i:=1 to n do read(a[i]);
search(0,0,0);
writeln(tot);
readln;
end. -
02009-08-08 10:29:46@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0msFunction fx(q:longint):boolean;
var l:longint;
begin
for l:=2 to round(sqrt(q))+1 do if q mod l=0 then exit(false);
exit(true);
end;Procedure search(x:longint;sum:int64);
var i:integer;
begin
for i:=c[x-1] to n do if b[i] then
begin
c[x]:=i;
b[i]:=false;
sum:=sum+a[i];
if x=k then begin if fx(sum) then sn:=sn+1; end
else search(x+1,sum);
b[i]:=true;
sum:=sum-a[i];
end;
end;Begin
readln(n,k);
for j:=1 to n do read(a[j]);
for j:=1 to n do b[j]:=true;
c[0]:=1;
sn:=0;
search(1,0);
writeln(sn);
end. -
02009-08-06 19:44:25@
深搜
农夫山泉 -
02009-08-02 21:15:28@
特别注意:本题是要求使和为素数的情况有多少种,并不是求有多少种素数
郁闷ING
-
02009-08-02 16:49:31@
基础DFS的变形!
a存储输入的数字。 b记录使用 增加一个c数组,标志每次搜入时到达第几个数,再往下搜时,从上次搜到的数开始而不是第一个数,否则重复了(同自然数拆分问题,不可重复)
貌似这就是楼下cinderaller的问题,用的是a,运行起来就乱了
Var n,k,sn,j:0..20;
a:array[0..20]of 0..5000000;
b:array[1..20]of boolean;
c:array[0..20]of 0..20;Function fx(q:longint):boolean;
var l:longint;
begin
for l:=2 to round(sqrt(q))+1 do if q mod l=0 then exit(false);
exit(true);
end;Procedure search(x:longint);
var i:integer;
begin
for i:=c[x-1] to n do if b[i] then
begin
c[x]:=i;
b[i]:=false;
sum:=sum+a[i];
if x=k then begin if fx(sum) then sn:=sn+1; end
else search(x+1);
b[i]:=true;
sum:=sum-a[i];
end;
end;Begin
readln(n,k);
for j:=1 to n do read(a[j]);
for j:=1 to n do b[j]:=true;
c[0]:=1;
sn:=0;
search(1);
writeln(sn);
end. -
02009-08-01 16:19:43@
{就是强悍}
program leo;
var a:array[1..20]of longint;
n,k,i,ans:longint;
function su(x:longint):boolean;
var i:longint;
begin
for i:=2 to round(sqrt(x)) do
if x mod i=0 then exit(false);
exit(true);
end;
procedure try(x,y,z:longint);
var i:longint;
begin
if y=k then begin if su(z) then inc(ans); end
else
if (y -
02009-08-01 09:37:56@
程序写35行就够了
为了避免重复,应该设置当前起始搜索点