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


 #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. 机器学习 scikit-learn 图谱

    scikit-learn 是机器学习领域非常热门的一个开源库,基于Python 语言写成.可以免费使用. 网址: http://scikit-learn.org/stable/index.html 上 ...

  2. BZOJ_3744_Gty的妹子序列

    BZOJ3744: Gty的妹子序列 https://lydsy.com/JudgeOnline/problem.php?id=3744 分析: 预处理出来每一块块首到所有位置的逆序对数. 查询时主席 ...

  3. ACM学习历程—HDU 5317 RGCDQ (数论)

    Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more an ...

  4. Oracle表空间维护总结

    1. 概念:表空间:最大的逻辑存储文件,与物理上的一个或多个数据文件对应,每个数据库至少拥有一个表空间,表空间的大小等于构成表空间的所有数据文件的大小总和,用于存储用户在数据库中存储的所有内容. 2. ...

  5. LMV实验

    在CentOS6.8上创建过程如下: #对需要创建lvm的卷进行磁盘分区[root@www ~13:40:48]#fdisk /dev/sde Device contains neither a va ...

  6. WPF学习系列之五(WPF控件)

    控件:    1.内容控件------这些控件能够包含嵌套的元素,为它们提供几乎无限的显示能力.内容控件包括Lable,Button 以及ToolTip类. 内容控件是更特殊的控件类型,它们可以包含( ...

  7. F - 棋盘问题

    F - 棋盘问题 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  8. MultiBinding的StringFormat参数问题

    在wpf的绑定中,我们会用到多值绑定,如下: <MultiBinding Mode="OneWay" StringFormat="{3}({0}/{1}):{2}& ...

  9. 浏览器原生 form 表单POST 数据的两种方式

    我们在提交表单的时候,form表单参数中会有一个enctype的参数.enctype指定了HTTP请求的Content-Type. 常用有两种:application/x-www-form-urlen ...

  10. 转: Charles 从入门到精通

    目录与版权 转载请保留顶部的 Charles 中国特惠内容,本文的内容主要包括: Charles 的简介 如何安装 Charles 将 Charles 设置成系统代理 Charles 主界面介绍 过滤 ...