Input
The test start with n which means that there are n cases.
The first line of each case gives two number p,q:the threshold and the size of excepted-word set.
The next line will give q words that you should ignore.
The next two lines are two document.
The document contains only words and all letters are lowercase.
The words are separated by blank space.
Output
If the two given documents are similar,print ’Yes’,or print ‘No’.
Sample Input
20.8 3i am ai am a boyi am a boy0.8 3i am ai am a boyi am a girl
Sample Output
YesNo
HINT
Source
第一次用Java做acm。
输入输出使用Scanner,配合String的split。非常方便
package A;
import java.util.*;
//import java.math.*;
public class Main {
public static void main(String[] arvs)
{
Scanner a = new Scanner(System.in);
int T = a.nextInt();
while ((T--) > 0)
{
if (!a.hasNextDouble()) break;
double p0 = a.nextDouble();
int n = a.nextInt();
HashSet<String> filter = new HashSet<String>();
HashMap<String, Integer> hash1 = new HashMap<String,Integer>();
HashMap<String, Integer> hash2 = new HashMap<String,Integer>();
for (int i=0;i<n;i++)
{
String f = a.next();
filter.add(f);
}
String line,words[];
while ((line = a.nextLine()).equals(""));
words = line.split(" ");
for (String w:words)
{
if (filter.contains(w))
continue;
if (hash1.containsKey(w))
hash1.put(w, hash1.get(w)+1);
else
hash1.put(w, 1);
}
double fenmu1 = 0;
for (int frequence:hash1.values())
{
fenmu1 += frequence*frequence;
}
fenmu1 = Math.sqrt(fenmu1);
while ((line = a.nextLine()).equals(""));
words = line.split(" ");
int common = 0;
for (String w:words)
{
if (filter.contains(w))
continue;
if (hash1.containsKey(w))
{
common += hash1.get(w);
}
if (hash2.containsKey(w))
hash2.put(w, hash2.get(w)+1);
else
hash2.put(w, 1);
}
double fenmu2 = 0;
for (int frequence:hash2.values())
{
fenmu2 += frequence*frequence;
}
fenmu2 = Math.sqrt(fenmu2);
double p = (double)common/(fenmu1*fenmu2);
if (p < p0)
System.out.println("No");
else
System.out.println("Yes");
}
}
}