【链接】 我是链接,点我呀:)
【题意】
【题解】
将直径相同的笔和笔盖放在同一个arraylist里面 然后写个hash,将颜色相同的优先配对 剩下的没办法只能委屈配对成"good"【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = 1000;
static class Task{
class Pair{
int x,type;
public Pair(int x,int type) {
this.x = x;this.type = type;
}
}
int n,m;
ArrayList<Pair> g[] = new ArrayList[N+10];
int cnt[] = new int[N+10];
public void solve(InputReader in,PrintWriter out) {
for (int i = 1;i <= N;i++) g[i] = new ArrayList<Pair>();
n = in.nextInt();m = in.nextInt();
for (int i = 1;i <= n;i++) {
int x,y;
x = in.nextInt();y = in.nextInt();
g[y].add(new Pair(x,1));
}
for (int j = 1;j <= m;j++) {
int x,y;
x = in.nextInt();y = in.nextInt();
g[y].add(new Pair(x,2));
}
long ans1 = 0,ans2 = 0;
for (int i = 1;i <= N;i++) {
for (int j = 1;j <= N;j++) cnt[j] = 0;
int len = g[i].size();
for (int j = 0;j < len;j++)
{
Pair temp = g[i].get(j);
if (temp.type==1) {
cnt[temp.x]++;
}
}
long pair_beautiful = 0,pair_normal=0;
for (int j = 0;j < len;j++)
{
Pair temp = g[i].get(j);
if (temp.type==2) {
if (cnt[temp.x]>0) {
cnt[temp.x]--;
pair_beautiful++;
}else pair_normal++;
}
}
long temp1 = 0;
for (int j = 1;j <= N;j++) {
temp1+=cnt[j];
}
pair_normal = Math.min(temp1, pair_normal);
ans1+=pair_normal;ans2+=pair_beautiful;
}
out.println((ans1+ans2)+" "+ans2);
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}