zoukankan      html  css  js  c++  java
  • 【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());
            }
        }
    }
    
  • 相关阅读:
    [北京省选集训2019]生成树计数
    阿里云轻量级服务器的日常操作
    阿里云轻量级服务器上搭建jdk、Tomcat、mysql、zookeeper步骤!!!
    mysql如何记录数据的创建时间和更新时间??
    解决ssm中文乱码问题,上传文件中文乱码的问题
    zookeeper的安装配置问题;
    zookeeper解决启动提示:找不到或者无法加载主类org. apache. zookeeper. server. guorum. QuorumPeerMlain的问题
    《数据采集与网络爬虫》之数据解析
    《数据采集与网络爬虫》环境篇
    《数据采集与网络爬虫》之抓取网页
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10507026.html
Copyright © 2011-2022 走看看