p1478 陶陶摘蘋果(公升級版) **:
總:把力氣從小到大排序,判斷是否能摘到,累加。
var
j,ans,n,s,h,h1,i:longint;
x,y:array[1..5000]of longint;
procedure
init;
var i:longint;
begin
readln(n,s);
readln(h,h1);
inc(h,h1);
for i:=1
to n do
read(x[i],y[i]);
end;
procedure
sort;
var i,j,t:longint;
begin
for i:=1
to n-1
dofor j:=i+1
to n do
if y[i]>y[j] then
begin
t:=x[i]; x[i]:=x[j]; x[j]:=t;
t:=y[i]; y[i]:=y[j]; y[j]:=t;
end;
end;
procedure
main;
var i,t:longint;
begin
t:=0; ans:=0;
for i:=1
to n do
if x[i]<=h then
if t<=s then
begin
if (t+y[i])>s then
begin
write(ans); exit;
end;
inc(ans); inc(t,y[i]);
end;
write(ans);
end;
begin
init;
sort;
main;
end.
p1618 三連擊(公升級版)**:
總:找那個什麼約數。
var
i,a,b,c,h1,h2,p,ss:longint;
j,k,j1,k1:real;
x:array[-1..100] of longint;
bo:boolean;
procedure
try1
(i:longint);
begin
x[i mod
10]:=1; x[i div
10mod
10]:=1; x[i div
100]:=1;
end;
begin
readln(a,b,c);
bo:=false;
for i:=123
to987
dobegin
if (j1*i>=1000) or (k1*i>=1000) then
break;
j:=b*i/a; k:=c*i/a;
if (trunc(j)=j) and (trunc(k)=k) then
begin
h1:=trunc(j); h2:=trunc(k);
p:=0;
try1(i); try1(h1); try1(h2);
for ss:=1to9
doif x[ss]>=1
then
begin
inc(p); x[ss]:=0;
end;
if p=9
then
begin
writeln(i,' ',h1,' ',h2); bo:=true;
end;
end;
end;
if bo=false
then
writeln('no!!!');
end.
p1579 哥德**猜想(公升級版)**:
總:列舉兩個質數,判斷第三個數。
var
n,i,j:longint;
function
try1
(x:longint):boolean;
var xx:longint;
begin
if x<2
then
exit(false);
for xx:=2
to trunc(sqrt(x)) do
if x mod xx=0
then
exit(false);
exit(true);
end;
begin
readln(n);
for i:= 2
to n-1
doif try1(i) then
for j:= 2
to n-i do
if (try1(j)) and (try1(n-i-j)) then
begin
writeln(i,' ',j,' ',n-i-j);
halt;
end;
end.
p2089 烤雞 **:
總:深搜。
type
data=array [1..10] of longint;
var
n:longint;
ans:array [0..10000] of data;
t:data;
procedure
search
(d:longint;a:data);
var
sum,i:longint;
begin
if d=10
then
begin
sum:=0;
for i:=1
to10
do inc(sum,a[i]);
if sum=n then
begin
inc(ans[0,1]);
ans[ans[0,1]]:=a;
end;
exit;
end;
a[d+1]:=1; search(d+1,a);
a[d+1]:=2; search(d+1,a);
a[d+1]:=3; search(d+1,a);
end;
procedure
print;
var i,j:longint;
begin
for i:=1
to ans[0,1] do
begin
for j:=1
to10
dowrite(ans[i,j],' ');
writeln;
end;
end;
begin
read(n);
search(0,t);
writeln(ans[0,1]);
print;
end.
總:烤雞挺好吃! 新手村 Boss戰 入門綜合練習2 Cantor表
題目鏈結 按照從右上到左下的斜對角來看,每條對角線可以分成1個數字 2個數字 3個數字 對於乙個n,我們可以先找出來是在第幾層的,1是第一層,2 3是第二層,4 6是第三層 層數標號11 22 3 34 6 45 10 那麼顯然,k k 1 2 k 1 k2 時,有第 n 個表示式在第k層 其實這時...
洛谷訓練新手村之「BOSS戰 入門綜合練習1」題解
題目大意 陶陶有s點體力值,每個蘋果消耗體力值,問s體力值最多能摘多少蘋果。解題思路 首先過濾掉摘不到的蘋果。其次從小到大排序,貪心思想 優先選擇消耗體力值小的蘋果。實現 如下 include using namespace std const int maxn 5050 int n,m,s,a,b...
新手村之迴圈!迴圈!迴圈!
p1008 三連擊 總 優美的暴力或打表。var i,j,a,b,c longint v array 0.10 of boolean f boolean begin for i 123 to345 dobegin fillchar v,sizeof v 0 a i b i 2 c i 3 for j...