import java.util.Arrays;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
private static Scanner cin;
private static int m;
private static int n;
private static int k;
private static int l;
private static int d;
public static void main(String args[]) throws Exception {
cin = new Scanner(System.in);
String t = cin.nextLine();
String[] v = t.split(" ");
m = Integer.valueOf(v[0]);
n = Integer.valueOf(v[1]);
k = Integer.valueOf(v[2]);
l = Integer.valueOf(v[3]);
d = Integer.valueOf(v[4]);
int x,y,p,q;
TreeMap<Spliter,Integer> tmK = new TreeMap<>();
TreeMap<Spliter,Integer> tmL = new TreeMap<>();
for(int i=0;i<d;i++) {
t = cin.nextLine();
v = t.split(" ");
x = Integer.valueOf(v[0]);
y = Integer.valueOf(v[1]);
p = Integer.valueOf(v[2]);
q = Integer.valueOf(v[3]);
//the same column, x is the same, spliter is L
if(x == p) {
Spliter s = new Spliter((y+q)/2);
if(tmL.containsKey(s)) {
int count = tmL.get(s);
tmL.replace(s, new Integer(count+1));
}else {
tmL.put(s, 1);
}
}
//the same row, y is the same ,spliter is K
else if(y == q) {
Spliter s = new Spliter((x+p)/2);
if(tmK.containsKey(s)) {
int count = tmK.get(s);
tmK.put(s, new Integer(count+1));
}else {
tmK.put(s, 1);
}
}
}
SpliterCount[] scK = new SpliterCount[tmK.size()];
SpliterCount[] scL = new SpliterCount[tmL.size()];
Entry<Spliter,Integer> e;
int[] karray = new int[k];
int[] larray = new int[l];
for(int i=0,size=tmK.size();i<size;i++) {
e = tmK.pollFirstEntry();
SpliterCount sct = new SpliterCount(e.getKey(),e.getValue());
scK[i] = sct;
}
Arrays.sort(scK);
for(int i=0;i<k;i++) {
karray[i] = scK[scK.length-i-1].getSpliter().getSpliterLine();
}
Arrays.sort(karray);
for(int i=0,size=tmL.size();i<size;i++) {
e = tmL.pollFirstEntry();
SpliterCount sct = new SpliterCount(e.getKey(),e.getValue());
scL[i] = sct;
}
Arrays.sort(scL);
for(int i=0;i<l;i++) {
larray[i] = scL[scL.length-i-1].getSpliter().getSpliterLine();
}
Arrays.sort(larray);
String ts = Arrays.toString(karray);
System.out.println(ts.substring(1, ts.length()-1).replace(",", ""));
ts = Arrays.toString(larray);
System.out.println(ts.substring(1, ts.length()-1).replace(",", ""));
}
}
class Spliter implements Comparable{
Integer spliterLine;
public Spliter(Integer aspliterLine) {
spliterLine = aspliterLine;
}
public Integer getSpliterLine() {
return spliterLine;
}
public int compareTo(Object arg0) {
Spliter s = (Spliter)arg0;
return spliterLine.compareTo(s.getSpliterLine());
}
public String toString() {
return String.format("spliterLine:%d,", spliterLine);
}
}
class SpliterCount implements Comparable{
Spliter spliter;
Integer count;
public SpliterCount(Spliter s, Integer c) {
spliter = s;
count = c;
}
public int compareTo(Object arg0) {
SpliterCount sc = (SpliterCount)arg0;
Spliter s2 = sc.getSpliter();
Integer c2 = sc.getCount();
if(spliter == s2 && count == c2) {
return 0;
}else if(count == c2) {
return - spliter.compareTo(s2);
}else {
return count.compareTo(c2);
}
}
public Spliter getSpliter() {
return spliter;
}
public Integer getCount() {
return count;
}
public String toString() {
return String.format("spliter:%s count=%d", spliter.toString(),count);
}
}
java实现 洛谷 P1056 排座椅
原创
©著作权归作者所有:来自51CTO博客作者热爱学习的发呆哥的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Vijos P1056 图形面积
矩形面积并
#include #define ios -
【贪心】排座椅
一、题目:排座椅(seat.cpp)时间限制: 1 Sec 内存限制: 64 MB题目描述上课的时候总有一些同学和前
贪心 i++ #include 二次排序 -
java实现 洛谷 P1056 排座椅
...
i++ java JAVA -
pci声卡怎么在bios上调
第二章 2. PCI驱动的基本流程 大纲 PCI声卡驱动的最简流程如下: 定义PCI ID表(请看PCI条目部分,此部分在第四章:《PCI资源管理》中)。 创建probe()回调。 创建remove()回调。
pci声卡怎么在bios上调 ci 回调函数 #include