No.1969 Count on Canton (ACM)
2008-11-06 22:15
239 查看
import java.io.*;
public class Main
{
String result = "";
int term =0,x=1,y=1;
public void find(int sum,int temp)
{
sum += ++temp;
if(sum<term) find(sum,temp);
else
{ //System.out.println("temp: "+temp+" sum :"+sum);
result = "";
if(temp%2==0){
x=temp;y=1;
for(int i=sum;i>term;i--)
{
x--;
y++;
}
result += ((Integer)x).toString()+"/"+((Integer)y).toString();
}else{
x=1;y=temp;
for(int i=sum;i>term;i--)
{
x++;
y--;
}
result = ((Integer)x).toString()+"/"+((Integer)y).toString();
}
}
}
public void readFile()throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = "start";
while(true){
str = br.readLine();
if(str.equals("")) break;
term = Integer.parseInt(str);
find(1,1);
System.out.println("TERM "+term+" IS "+result);
}
}
public static void main(String args[])throws Exception
{
new Main().readFile();
}
}
public class Main
{
String result = "";
int term =0,x=1,y=1;
public void find(int sum,int temp)
{
sum += ++temp;
if(sum<term) find(sum,temp);
else
{ //System.out.println("temp: "+temp+" sum :"+sum);
result = "";
if(temp%2==0){
x=temp;y=1;
for(int i=sum;i>term;i--)
{
x--;
y++;
}
result += ((Integer)x).toString()+"/"+((Integer)y).toString();
}else{
x=1;y=temp;
for(int i=sum;i>term;i--)
{
x++;
y--;
}
result = ((Integer)x).toString()+"/"+((Integer)y).toString();
}
}
}
public void readFile()throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = "start";
while(true){
str = br.readLine();
if(str.equals("")) break;
term = Integer.parseInt(str);
find(1,1);
System.out.println("TERM "+term+" IS "+result);
}
}
public static void main(String args[])throws Exception
{
new Main().readFile();
}
}
相关文章推荐
- POJ 1969---Count on Canton【数学问题】
- poj 1969 Count on Canton
- 算法思考: poj 1969 Count on Canton
- POJ 1969 Count on Canton(数学题,找规律)
- poj 1969 Count on Canton 摘规律
- (解题报告)POJ1969--Count on Canton(利用蛇形矩阵知识)
- POJ 1969 Count on Canton 笔记
- poj 1969 Count on Canton
- 【H - ECJTU_ACM 11级队员2012年暑假训练赛(2)】
- ACM经典算法之图论
- ACM 第四题 (2010-6-7 15:43)
- ACM_阶段性总结 ACM_动态规划(DP)
- A - Millennium&&http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=9661#problem/A
- 卡特兰数 Catalan数 ( ACM 数论 组合 )
- http://acm.hdu.edu.cn/showproblem.php?pid=1106&&排序
- hdu 3635 Dragon Balls(加权并查集)2010 ACM-ICPC Multi-University Training Contest(19)
- 【ACM暑假培训】1、穷举算法
- 寒冰王座(http://acm.hdu.edu.cn/showproblem.php?pid=1248)
- 【ACM暑假培训】递归算法4:马踏棋盘
- ACM学习历程—HDU5418 Victor and World(动态规划 && 状压)