Uva12210-A Match Making Problem
对于每个数字二分找到大于等于它的数,再暴力找到第一个小于它的数
#include<bits/stdc++.h> #define inf 0x3f3f3f3f const int maxn=; using namespace std; int b,s; int icase; int m[maxn+],w[maxn+]; int flag[maxn+]; int flagm[maxn+]; bool cmp(int a,int b){
return a>b;
} int firstmin(int val){
for(int i=;i<=s;i++){
if(w[i]>=val){
return i-;
}
}
return s;
} void solve(){ int x=b,y=;
memset(flag,,sizeof(flag));
memset(flagm,,sizeof(flagm));
sort(m+,m+b+);
sort(w+,w+s+);
for(int i=b;i>=;i--){
int t=x;
int p=lower_bound(w+,w+s+,m[i])-w;
int q=firstmin(m[i]);
// printf("%d %d\n",p,q);
if(p==s+){
if(!flag[q]){
flag[q]=;
x--;
} else{
for(int h=q-;h>=;h--){
if(!flag[h]){
flag[h]=;
x--;
break;
}
}
}
} else if(q==){
if(!flag[p]){
flag[p]=;
x--;
} else {
for(int h=p+;h<=s;h++){
if(!flag[h]){
flag[h]=;
x--;
break;
}
}
}
} else if(p!=s+&&q!=){
int r=inf,v=inf;
if(!flag[p]){
r=abs(m[i]-w[p]);
}
if(!flag[q]){
v=abs(m[i]-w[q]);
}
if(!flag[p]&&!flag[q]){
if(v<=r){
flag[q]=;
x--;
} else {
flag[p]=;
x--;
}
} else if(flag[p]&&!flag[q]){
flag[q]=;
x--;
} else if(!flag[p]&&flag[q]){
flag[p]=;
x--;
} else if(flag[p]&&flag[q]){
int f=;
for(int h=q+;h<p;h++){
if(!flag[h]){
flag[h]=;
x--;
f=;
break;
}
}
if(!f){
int ff=,fff=;
for(int h=p+;h<=s;h++){
if(!flag[h]){
ff=h;
break;
}
}
for(int h=q-;h>=;h--){
if(!flag[h]){
fff=h;
break;
}
}
if(ff&&fff){
if(abs(m[i]-w[ff])<=abs(m[i]-w[fff])){
flag[ff]=;
x--;
} else {
flag[fff]=;
x--;
}
} else if(ff&&!fff){
flag[ff]=;
x--;
} else if(!ff&&fff){
flag[fff]=;
x--;
}
}
} }
if(t==x+) flagm[i]=;
}
for(int i=;i<=b;i++){
if(!flagm[i]) {
y=i;
break;
}
}
printf("%d",x);
if(x) printf(" %d",m[y]);
} void input(){
for(int i=;i<=b;i++){
scanf("%d",&m[i]);
}
for(int i=;i<=s;i++){
scanf("%d",&w[i]);
}
printf("Case %d: ",++icase);
} int main()
{
//freopen("e:\\duipai\\out1.txt","w",stdout);
while(scanf("%d%d",&b,&s)!=EOF&&(b||s)){
input();
solve();
printf("\n");
}
return ;
}
Uva12210-A Match Making Problem的更多相关文章
- Python中的正则表达式regular expression
1 match = re.search(pat,str) If the search is successful, search() returns a match object or None o ...
- Codeforces Gym 100650B Countdown DFS
Problem B: CountdownTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/conte ...
- (zhuan) Notes on Representation Learning
this blog from: https://opendatascience.com/blog/notes-on-representation-learning-1/ Notes on Repr ...
- HGOI 20190708 题解
Problem A 拿出勇气吧 幸运数字每一位是$4$或者$7$,现在给出一个数字每位数位上数的和为n,求出最小的幸运数n 对于100%的数据,$n\leq 10^6$ Sol : 显然本题要求数的长 ...
- Description Resource Path Location Type Java compiler level does not match the version of the installed Java project facet Unknown Faceted Project Problem (Java Version Mismatch)
project 编译问题,需要三处的jdk版本要保持一致,才能编译通过. 1.在项目上右键properties->project Facets->修改右侧的version 保持一致 2. ...
- svn:Repository UUID 'XXX' doesn't match expected UUID 'YYY'
About a month ago, CodePlex have upgraded their TFS servers to to TFS 2010. While this transition wa ...
- HDU 3416 Marriage Match IV (求最短路的条数,最大流)
Marriage Match IV 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/Q Description Do not si ...
- Scala学习文档-样本类与模式匹配(match,case,Option)
样本类:添加了case的类便是样本类.这种修饰符可以让Scala编译器自动为这个类添加一些语法上的便捷设定. //样本类case class //层级包括一个抽象基类Expr和四个子类,每个代表一种表 ...
- [Regular Expressions] Match the Start and End of a Line
We can use: ^: match the beginning $: match the end Let's say we have the string like the following: ...
随机推荐
- BZOJ 1677 [Usaco2005 Jan]Sumsets 求和:dp 无限背包 / 递推【2的幂次方之和】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1677 题意: 给定n(n <= 10^6),将n分解为2的幂次方之和,问你有多少种方 ...
- SpringMVC拦截器的配置与使用详解
一.SpringMVC拦截器简介 Spring MVC的处理器拦截器类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理.在springmvc中,定义拦截 ...
- Log4j 与 logback对比、及使用配置
二.参考文档 1.Log4j 与 logback对比.及使用配置
- struts2的通配符与动态方法调用
1.Action标签中的method属性 我们知道action默认的执行的方法是execute方法,但是一个action只执行一个方法我们觉得有点浪费,我们希望在一个action中实现同一模块的不同功 ...
- 【Shell】Linux 一行 多命令
http://www.cnblogs.com/koreaseal/archive/2012/05/28/2522178.html 要实现在一行执行多条Linux命令,分三种情况: 1.&&am ...
- Nginx HTTP Server相关
一.Nginx安装: 采取手动编译安装 对多种重要的选项进行配置 安装前提:常用工具和库,GCC PCRE(Rewrite模块需要) pcre-devel(源码) zlib zlib-devel(源码 ...
- python下setuptools安装
python下的setuptools带有一个easy_install的工具,在安装python的每三方模块.工具时很有用,也很方便.安装setuptools前先安装pip,请参见<pytho ...
- bzoj 3522: Hotel dfs
题目大意 在无边权树上求三个点,使两两点的距离等.求方案数\((n\leq 5000)\) 题解 我们知道三个点在树上的关系只有两种 三点共链 三点不共连 (这不是废话吗) 我们发现三点共链肯定不满足 ...
- Scala学习——类,继承,接口(中)
基本类的使用:(初) package com.dtspark.scala.basics /** * trait是一个接口 * 接口的第一次继承用extends,多继承时用with * 多继承时,如果这 ...
- 转学习LINUX的建议
作为一个新人,怎样学习嵌入式Linux?被问过太多次,特写这篇文章来回答一下.在学习嵌入式Linux之前,肯定要有C语言基础.汇编基础有没有无所谓(就那么几条汇编指令,用到了一看就会).C语言要学到什 ...