usaco 2.1 frac1 2008.5.10
2016-02-05 11:09
337 查看
usaco 2.1 frac1 2008.5.10
{
ID:
PROG: frac1
LANG: PASCAL
}
program p_frac1;
const fin='frac1.in';fout='frac1.out';
type
arr1=array[1..8000,1..2]of longint;
arr2=array[1..8000]of real;
var i,j,k,p,w,n:longint;
a:arr1;b:arr2;
f1,f2:text;
procedure qsort(i,j:longint);
var
l,r,g:longint;x,y:real;
begin
l:=i;r:=j;
x:=b[(l+r) div 2];
repeat
while b[l]<x do inc(l);
while b[r]>x do dec(r);
ifl<=r then
begin
y:=b[l];b[l]:=b[r];b[r]:=y;
g:=a[l,1];a[l,1]:=a[r,1];a[r,1]:=g;
g:=a[l,2];a[l,2]:=a[r,2];a[r,2]:=g;
inc(l);dec(r);
end;
until l>r;
if r>i then qsort(i,r);
if l<j then qsort(l,j);
end;
function gcd(a,b:integer):integer;
begin
ifb=0 then gcd:=a
else gcd:=gcd (b,a mod b);
end ;
{------------------------------}
begin
assign(f1,fin);reset(f1);
assign(f2,fout);rewrite(f2);
read(f1,n);
writeln(f2,'0/1');
p:=0;
fori:=2 to n do
begin
inc(p);b[p]:=1/i;a[p,1]:=1;a[p,2]:=i;
for j:=2 to i-1 do
if gcd(i,j)=1 then
begin inc(p);b[p]:=j/i;
a[p,1]:=j;a[p,2]:=i;
end;
end;
qsort(1,p);
for i:=1 to p do
writeln(f2,a[i,1],'/',a[i,2]);
writeln(f2,'1/1');
close(f1);close(f2);
end.
{
ID:
PROG: frac1
LANG: PASCAL
}
program p_frac1;
const fin='frac1.in';fout='frac1.out';
type
arr1=array[1..8000,1..2]of longint;
arr2=array[1..8000]of real;
var i,j,k,p,w,n:longint;
a:arr1;b:arr2;
f1,f2:text;
procedure qsort(i,j:longint);
var
l,r,g:longint;x,y:real;
begin
l:=i;r:=j;
x:=b[(l+r) div 2];
repeat
while b[l]<x do inc(l);
while b[r]>x do dec(r);
ifl<=r then
begin
y:=b[l];b[l]:=b[r];b[r]:=y;
g:=a[l,1];a[l,1]:=a[r,1];a[r,1]:=g;
g:=a[l,2];a[l,2]:=a[r,2];a[r,2]:=g;
inc(l);dec(r);
end;
until l>r;
if r>i then qsort(i,r);
if l<j then qsort(l,j);
end;
function gcd(a,b:integer):integer;
begin
ifb=0 then gcd:=a
else gcd:=gcd (b,a mod b);
end ;
{------------------------------}
begin
assign(f1,fin);reset(f1);
assign(f2,fout);rewrite(f2);
read(f1,n);
writeln(f2,'0/1');
p:=0;
fori:=2 to n do
begin
inc(p);b[p]:=1/i;a[p,1]:=1;a[p,2]:=i;
for j:=2 to i-1 do
if gcd(i,j)=1 then
begin inc(p);b[p]:=j/i;
a[p,1]:=j;a[p,2]:=i;
end;
end;
qsort(1,p);
for i:=1 to p do
writeln(f2,a[i,1],'/',a[i,2]);
writeln(f2,'1/1');
close(f1);close(f2);
end.
相关文章推荐
- usaco 2.1 sort3 2008.5.20
- usaco 2.1 holstein 2008.5.20
- PHP面向对象深入研究之【对象生成】
- 关于url路径的定义方式
- 1005 -
- wpftoolkit,好多wpf控件,有空可以用用
- 类型转换异常处理java.lang.RuntimeException
- 第4讲项目2——完成简单计算(4)
- 类型转换异常处理java.lang.RuntimeException
- 类型转换异常处理java.lang.RuntimeException
- Fedora21下安装VirtualBox及Mac虚拟机
- Swift中使用typealias定义一个闭包closure
- JSP中out.write()和out.print()的区别
- 第七章、闪电(3)正闪和云
- poj 2932 Coneology(扫描线+set)
- USACO 1.1 friday
- 【java工具类】【图片处理】从一整张图上加载任意一小块区域的图片
- Pyqt 获取打包二进制文件中的资源
- 论文《Face Alignment at 3000 FPS via Regressing Local Binary Features》笔记
- Windows内核研究总结