Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
基本的回溯题,咋这么少的人AC了呢。。贴AC代码Source Code Problem: 1078 User: yzhw Memory: 5728K Time: 313MS Language: Java Result: Accepted Source Code import java.util.*; import java.io.*; public class Main { static boolean used[]=new boolean[101]; static boolean flag,find; static boolean chk(int pos,int num1,int num2) { if(num1==1) { if(flag) return true; else { flag=find=true; if(chk(1,num2,num2)) return true; flag=false; return false; } } else if(pos>100) return false; else { for(int i=pos;i<=100;i++) { if(num1%i==0&&!used[i]) { used[i]=true; if(chk(pos+1,num1/i,num2)) return true; used[i]=false; } } return false; } } public static void main(String[] args) throws Exception{ Scanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int a,b; while(in.hasNextInt()) { a=in.nextInt(); b=in.nextInt(); if(a<b) { a=a+b; b=a-b; a=a-b; } flag=false; find=false; Arrays.fill(used, false); boolean res=chk(1,b,a); if(res) System.out.println(a); else if(find) System.out.println(b); else System.out.println(a); } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator