| ||||||||||
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 |
极品诡异,我在以下网址提交系统判断正确,poj上却判断错误,请管理员看一下如题,我在:http://acm.xtu.edu.cn/OnlineJudge/index.php/problem/read/id/1325 看到同样是这题,当然题号不同,但题目一样的,我用的是java,一摸一样的程序,xtu上判断AC,POJ判断WA,点解?xtu上memory市9972kb,time是62ms. 以下是我的程序: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(bf.readLine()); for(int i=0;i<n;i++){ int m=Integer.parseInt(bf.readLine()); boolean suf=false; Trie trie=new Trie(); String ss[]=new String[m]; for(int j=0;j<m;j++){ ss[j]=bf.readLine(); } for(String s:ss){ boolean ans=trie.insert(s); if(ans){ System.out.println("NO"); suf=true; break; } } if(!suf) System.out.println("YES"); } } } class Trie{ Node root=new Node(); boolean insert(String s){ Node node=root; boolean counterSuffix=false; char[] chs=s.toCharArray(); for(int i=0;i<chs.length;i++){ char c=chs[i]; Node temp=node.hm.get(c); if(temp==null){ temp=new Node(c); node.hm.put(c,temp); } if(temp.isLeft) counterSuffix=true; if(i==chs.length-1) temp.isLeft=true; node=temp; } return counterSuffix; } } class Node{ HashMap<Character,Node> hm=new HashMap<Character,Node>(); char value=' '; public Node(char v){ value=v; } public Node(){} boolean isLeft=false; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator