【链接】 我是链接,点我呀:)

【题意】

笔和笔盖
笔有颜色和直径
笔盖也有颜色和直径
笔盖和笔如果直径相等
那么称为good
如果笔盖和笔直径相等、颜色也相等,那么称为very good
问你怎样安排笔和笔盖才能让good最多的情况下very good也最多.

【题解】

将直径相同的笔和笔盖放在同一个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());
}
}
}

【Codeforces 159B】Matchmaker的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. java笔记线程方式1线程暂停yield

    public static void yield():暂停当前正在执行的线程对象,并执行其他线程. 让多个线程的执行更和谐,但是不能靠它保证一人一次. public class ThreadYield ...

  2. 私有CA和证书

    证书类型 证书授权机构的证书 服务器 用户证书 获取证书两种方法 使用证书授权机构: 生成签名请求(csr ) 将csr发送给CA 从CA处接收签名 自签名的证书: 自已签发自己的公钥 openSSL ...

  3. eslint 的配置

    安装 可以全局安装,也可以在项目下面安装. 如下是在项目中安装示例,只需要在 package.json 中添加如下配置,并进行安装: >"eslint": "^4. ...

  4. restful api 错误

    简介 随着移动开发和前端开发的崛起,越来越多的 Web 后端应用都倾向于实现 Restful API.Restful API 是一个简单易用的前后端分离方案,它只需要对客户端请求进行处理,然后返回结果 ...

  5. tomcat 参数调优

    JAVA_OPTS="-Xms2g -Xmx2g  -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath= ...

  6. Spring抽象JDBC,使用JdbcTemplate

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. 程序 从存储卡 内存卡 迁移到 SD卡

    程序 从存储卡 内存卡  迁移到 SD卡 如果你想移动其他软件,在应用市场界面,点击“管理 > 应用搬家”,点击需要转移的应用旁边的“移至SD卡”即可.

  8. Java屏幕截图及剪裁

    Java标准API中有个Robot类,该类可以实现屏幕截图,模拟鼠标键盘操作这些功能.这里只展示其屏幕截图. 截图的关键方法createScreenCapture(Rectangle rect) ,该 ...

  9. C# 调用带有输出参数的分页存储过程

    一.创建带有输出参数的分页存储过程 use StudentMISDB go select * from Course alter table Course go --update Course set ...

  10. 北大ACM(POJ1015-Jury Compromise)

    Question:http://poj.org/problem?id=1015 问题点:DP. Memory: 1352K Time: 94MS Language: C++ Result: Accep ...