【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- robotframework - 框架做接口自动化post请求
1.做get请求之前先安装 Request库,参考github上链接 :https://github.com/bulkan/robotframework-requests/#readme 2.请求&a ...
- ROS-USB摄像头
前言:演示使用usb摄像头功能,推荐使用方法二. 首先要有一个usb摄像头,本次使用的是罗技(Logitech)摄像头. 一.使用软件库里的uvc-camera功能包 1.1 检查摄像头 lsusb ...
- [读书笔记2]《C语言嵌入式系统编程修炼》
第3章 屏幕操作 3.1 汉字处理 现在要解决的问题是,嵌入式系统中经常要使用的并非是完整的汉字库,往往只是需要提供数量有限的汉字供必要的显示功能.例如,一个微波炉的LCD上没有必要提供显示&qu ...
- 计算几何值平面扫面poj2932 Coneology
Coneology Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4097 Accepted: 859 Descript ...
- [ CodeForces 1059 D ] Nature Reserve
\(\\\) \(Description\) 你现在有\(N\)个分布在二维平面上的整点\((x_i,y_i)\),现在需要你找到一个圆,满足: 能够覆盖所有的给出点 与\(x\)轴相切 现在需要你确 ...
- 2057. [ZLXOI2015]殉国
★☆ 输入文件:BlackHawk.in 输出文件:BlackHawk.out 评测插件 时间限制:0.05 s 内存限制:256 MB [题目描述] 正义的萌军瞄准了位于南极洲的心灵 ...
- AndroidStudio3.0 Canary 8注解报错Annotation processors must be explicitly declared now.
体验最新版AndroidStudio3. Canary 8的时候,发现之前项目的butter knife报错,用到注解的应该都会报错 Error:Execution failed for task ' ...
- C++11:using 的各种作用
C++11中using关键字的主要作用是:为一个模板库定义一个别名. 文章链接:派生类中使用using别名改变基类成员的访问权限 一.<Effective Modern C++>里有比较 ...
- 扩增子分析QIIME2-3数据导出Exporting data
# 激活工作环境 source activate qiime2-2017.8 # 建立工作目录 mkdir -p qiime2-exporting-tutorial cd qiime2-exporti ...
- vue(数据改变,DOM不渲染问题)
1.组件内部,属性值地址空间内引用地址改变,DOM不能渲染. 问题举例:this.items = [[],[],[],[]] 1.在items 中,修改任意一项数组中的值,DOM是不会更新的,2.解决 ...