【Codeforces 159B】Matchmaker
【链接】 我是链接,点我呀:)
【题意】
笔和笔盖
笔有颜色和直径
笔盖也有颜色和直径
笔盖和笔如果直径相等
那么称为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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- struct框架
配置文件struct-config.xml<?xml version="1.0"encoding="UTF-8"?><!DOCTYPE str ...
- SSM整合配置错误记录
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dic ...
- CodeForces 515C Drazil and Factorial (水题)
题意:给出含有 n 个只有阿拉伯数字的字符串a,设定函数F(a) = 每个数字的阶乘乘积 .需要找出 x,使得F(x) = F(a),且组成 x 的数字中没有0和1.求最大的 x 为多少. 析:最大, ...
- sshd服务器搭建管理和防止暴力破解
1.1 Linux服务前期环境准备,搭建一个RHEL7环境 1.2 sshd服务安装-ssh命令使用方法 1.3 sshd服务配置和管理 1.4 防止SSHD服务暴力破解的几种方式 1.1 Linux ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- web api 二
接着上一回说,上回说到,web api有几种访问方式,具体有几种,我还真没去研究过,但是这里打算从get.post.put.delete四种请求方式分别谈谈基础类型(包括int/string/date ...
- 数据传递--------博客-----------springMVC源码分析--RequestToViewNameTranslator请求到视图名称的转换
参考来源:http://blog.csdn.net/qq924862077/article/details/54286976?utm_source=gold_browser_extension Req ...
- Ray Wenderlich 的 Objective-C编码规范
由于我正在准备模仿饿了么这个app,到时可能有些iOS开发者参与进来.这时如果每个人的Objective-C编码风格都不一样,这样不易于保持代码一致性和难以Code Review.所以我在网上搜索到 ...
- Java 遍历Map对象的4种方法
http://blog.csdn.net/tjcyjd/article/details/11111401
- 创建http对象
package test; import java.net.HttpURLConnection;import java.net.URL; import javax.servlet.http.HttpS ...