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

【题意】

笔和笔盖
笔有颜色和直径
笔盖也有颜色和直径
笔盖和笔如果直径相等
那么称为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. SqlServer数据库性能优化详解

    数据库性能优化详解 性能调节的目的是通过将网络流通.磁盘 I/O 和 CPU 时间减到最小,使每个查询的响应时间最短并最大限度地提高整个数据库服务器的吞吐量.为达到此目的,需要了解应用程序的需求和数据 ...

  2. bzoj 4326: NOIP2015 运输计划【树链剖分+二分+树上差分】

    常数巨大,lg上开o2才能A 首先预处理出运输计划的长度len和lca,然后二分一个长度w,对于长度大于w的运输计划,在树上差分(d[u]+1,d[v]+1,d[lca]-2),然后dfs,找出所有覆 ...

  3. E - Cheap Kangaroo(求多个数的最大公约数)

    Description There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants t ...

  4. ACM_发工资(简单贪心)

    发工资咯: Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为广财大的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日 ...

  5. Hbase源码分析:RPC概况

    RPC是hbase中Master,RegionServer和Client三者之间通信交流的纽带.了解hbase的rpc机制能够为通过源码学习hbase奠定良好的基础.因为了解了hbase的rpc机制能 ...

  6. 上传一个npm包

    1.先创建一个npm账号 https://www.npmjs.com/signup 2.在cmd里输入命令进入项目文件夹 3.使用npm init 命令创建一个package.json(确保nodej ...

  7. axios 正确打开方式

    一.安装1. 利用npm安装npm install axios --save2. 利用bower安装bower install axios --save3. 直接利用cdn引入<script s ...

  8. Spartan6系列之芯片配置模式详解

    1.   配置概述 Spartan6系列FPGA通过把应用程序数据导入芯片内部存储器完成芯片的配置.Spart-6 FPGA可以自己从外部非易失性存储器导入编程数据,或者通过外界的微处理器.DSP等对 ...

  9. vps 虚拟服务器 教程 ( Virtual Private Server 虚拟专用服务器 )

    VPS是虚拟服务器的意思.他是通过软件在独立服务器上划分出来的一部分资源.从而虚拟出一个服务器.他拥有独立的IP.独立的操作系统.以及用户名和密码.在功能和使用方法上与服务器一模一样.用户也可以根据自 ...

  10. Windows开源Web服务器性能和压力测试工具

    linux有很多开源工具用来测试服务器负载,而windows上非常少,几乎没有除了几个复杂的JMeter WET等 将两个好用的工具是Linux版本通过Cygwin移植过来,方便广大windows人员 ...