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());
            }
        }
    }
    
  • 相关阅读:
    Revit二次开发示例:DisableCommand
    Revit二次开发示例:DesignOptions
    C# 非模式窗体show()和模式窗体showdialog()的区别
    Revit二次开发示例:DeleteObject
    被动永远做不好运维
    sudo开发常用命令总结
    ansible 配置了端口在host文件但是还要走22 ip:60001 ansible_ssh_port=60001
    ansible wc -l 对结果值取大小的操作
    mha切换脚本可用的
    mongoDB自动杀执行时间的连接
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10507026.html
Copyright © 2011-2022 走看看