对于每个数字二分找到大于等于它的数,再暴力找到第一个小于它的数


 #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的更多相关文章

  1. Python中的正则表达式regular expression

    1 match = re.search(pat,str)  If the search is successful, search() returns a match object or None o ...

  2. Codeforces Gym 100650B Countdown DFS

    Problem B: CountdownTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/conte ...

  3. (zhuan) Notes on Representation Learning

    this blog from: https://opendatascience.com/blog/notes-on-representation-learning-1/   Notes on Repr ...

  4. HGOI 20190708 题解

    Problem A 拿出勇气吧 幸运数字每一位是$4$或者$7$,现在给出一个数字每位数位上数的和为n,求出最小的幸运数n 对于100%的数据,$n\leq 10^6$ Sol : 显然本题要求数的长 ...

  5. 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. ...

  6. 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 ...

  7. HDU 3416 Marriage Match IV (求最短路的条数,最大流)

    Marriage Match IV 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/Q Description Do not si ...

  8. Scala学习文档-样本类与模式匹配(match,case,Option)

    样本类:添加了case的类便是样本类.这种修饰符可以让Scala编译器自动为这个类添加一些语法上的便捷设定. //样本类case class //层级包括一个抽象基类Expr和四个子类,每个代表一种表 ...

  9. [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: ...

随机推荐

  1. 常用JS组件整理

    1.漂亮的弹出层----artDialog http://aui.github.io/artDialog/ 2.弹出层 ------layer http://sentsin.com/jquery/la ...

  2. enable nested VT in VM

    问题描述: 处理器支持VT-x,并且已经在BIOS中开启了VT-x.在host os上用VMware Workstation安装了一个Ubuntu虚拟机,在虚拟机中执行“cat /proc/cpuin ...

  3. 文件操作:os模块与os.path模块

    一.os与os.path 原创:http://www.cnblogs.com/lovemo1314/archive/2010/11/08/1871781.html os模块用于处理文件及文件夹,包括文 ...

  4. C字符串末尾的'\0'问题

    C语言的字符串要注意最后一位默认是'/0'的问题.这是一个易错点. strlen()计算长度时不考虑末尾的'\0' //例1 void test1() { ]; "; strcpy( str ...

  5. Maven-将jar包安装到本地仓库

    因为项目需要,使用的是sqlserver数据库,但是却找不到其对应的pom依赖,所以需要将本地jar包安装到本地仓库,定义pom依赖.以此为例,其他jar包均可参考该方式 cmd命令语句: mvn i ...

  6. CentOS 6以下版本 支持Ext4

    CentOS默认是不支持Ext4.所以你需要处理一下才行. 使用环境使用的是CentOS5.8 内核是  2.6.18-238.19.1.el5 其实CentOS 5.8 里面是有 ext4 模块的, ...

  7. 【LeetCode】040. Combination Sum II

    题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...

  8. Ubuntu 复制文件,修改文件名

    复制 cp a b   (a为旧的,b为新的) 修改 mv a b (a为旧的,b为新的)

  9. 三 lambda表达式有什么用

    (转载: https://mp.weixin.qq.com/s/-PHOc6p-qKJBktle28AUgA) 一: 直接把代码块赋值给变量 我们知道,对于一个Java变量,我们可以赋给其一个“值”. ...

  10. 使用外网控制你的STM32单片机

    转自:http://blog.csdn.net/xdxlove/article/details/50837459 本文章假设读者已经在STM32单片机上成功移植LWIP,且已经实现在局域网内控制STM ...