讨论 / 怎么做呀?
Wych 2013-01-23 16:54:00
点我顶贴 收藏 删除
想不出来,问问大牛,什么思路和公式?
#1 Jollwish@2008-08-20 21:30:00
回复 删除
走Z字吗!判断一下方向就行了

var i,n,a,b,s:integer;

begin

readln(n);

a:=1;

b:=1;

s:=2;

for i:=2 to n do

begin

if (a=s-1)and odd(s) or (a=1)and(s mod 2=0) then

begin

inc(s);

if odd(s) then

begin

a:=1;

b:=s-1;

end

else

begin

a:=s-1;

b:=1;

end;

continue;

end;

if odd(s) then

begin

inc(a);

dec(b);

end

else

begin

dec(a);

inc(b);

end;

end;

writeln(a,’/’,b);

end.

#2 wwww@2008-08-21 20:46:00
回复 删除
短一点,利用三角形数

var i,z,b,c,n,m,a:longint;

begin

read(n);

m:=0;i:=0;

while m<n do

begin

i:=i+1;

m:=m+i;

end;

m:=m-i;

if i mod 2=0 then begin a:=1;b:=i;c:=1;end else begin a:=i;b:=1;c:=-1;end;

for i:=m to n-2 do begin a:=a+c;b:=b-c;end;

write(a,’/’,b);

end.

#3 飞雪天涯@2008-11-13 00:02:00
回复 删除
//Simulation

#include<fstream>

#include<iostream>

using namespace std;

#define fin cin

#define fout cout

//ifstream fin ("cantor.in");

//ofstream fout ("cantor.out");

long n,fraction_son,fraction_mum;

void input(){

fin>>n;

}

void fractions(){

fraction_son=fraction_mum=1;

long k=1,sum=2,module=1;

int fraction_son_add=-1,fraction_mum_add=1;

while (k<n){

if (module==sum-1){

fraction_son_add=-fraction_son_add;

fraction_mum_add=-fraction_mum_add;

sum++;k++;module=1;

if (fraction_son_add==1){

fraction_son=1;

fraction_mum=sum-1;

}

else{

fraction_son=sum-1;

fraction_mum=1;

}

}

else{

k++;module++;

fraction_son+=fraction_son_add;

fraction_mum+=fraction_mum_add;

}

}

}

void output(){

fout<<fraction_son<<’/’<<fraction_mum<<endl;

}

int main (void){

input();

fractions();

output();

return 0;

}

#4 zsx@2009-09-16 18:09:00
回复 删除
不能在简了~

var n,s,i:longint;

begin

read(n);

for i:=1 to n do begin

s:=s+i;

if s>=n then break;end;

if odd(i)=true then

write(s-n+1,’/’,i+1-(s-n+1))

else write(i+1-(s-n+1),’/’,s-n+1);

end.

#5 JasonX@2010-08-16 12:47:00
回复 删除
var s,i,j,n:longint;

begin

read(n);

for i:=1 to n do

if i*(i+1)/2>=n then begin

s:=i-1; break; end;

writeln(n-s*(s+1) div 2,'/',s+2-n+s*(s+1) div 2);

end.

#6 lyc@2010-09-23 09:57:00
回复 删除
var

n,s,o:longint;

begin

readln(n);

o:=1;

s:=n;

while s-o>0 do

begin

s:=s-o;

o:=o+1;

end;

writeln((o-s+1),'/',s);

end.

#7 wtta@2010-09-23 11:08:00
回复 删除
方向最重要

const

fx1:array[1..4]of integer=(1,-1,0,1);

fy:array[1..4]of integer=(0,1,1,-1);

var

n,i,x,y,f,wfwegfg:integer;

begin

readln(n);

x:=1;

y:=1;

f:=1;

i:=1;

while i<n do

begin

x:=x+fx1[f];

y:=y+fy[f];

inc(i);

if f=1 then f:=2 else

if (f=2) and (x=1) then

f:=3 else

if f=3 then f:=4 else

if (f=4) and (y=1) then f:=1;

end;

writeln(y,'/',x);

readln;

end.

#8 lyc@2010-09-23 11:41:00
回复 删除
数据超弱....题目没看清var

n,s,o:longint;

begin

readln(n);

o:=1;

s:=n;

while s-o>0 do

begin

s:=s-o;

o:=o+1;

end;

writeln((o-s+1),'/',s);

end.

一个错的程序 A了......

#9 LJHZLH@2013-01-23 16:54:00
回复 删除
CPP方法

#include<cstdio>

#include<cstdlib>

#include<cmath>

int main()

{

int n;

if(n == 2) printf("1/2");

else if(n == 3) printf("2/1");

while(scanf("%d",&n)==1)

{

int k = (int)floor((sqrt(8.0*n+1)-1)/2-1e-9)+1;

int s = k*(k+1)/2;

printf("%d/%d\n",s-n+1,k-s+n);

}

system("pause");

}

利用的是代数

#10 1700671432@2017-09-15 13:36:44
回复 删除
#include <cstdio>

#include <cstring>

int n,m;

int main()

{

scanf("%d",&n);

m=1;

while(n>m)

{

n-=m;

m++;

}

if(m%2==1)printf("%d/%d",m-n+1,n);

else printf("%d/%d",n,m-n+1);

}

查看更多回复
提交回复