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


 #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. Android sdk 搭建

    下载安装 http://pan.baidu.com/wap/share/home?uk=67915989&third=0 搭建Android环境时,无论使用的Eclipse还是Android ...

  2. 重新拾取:ASP.NET Core WebApi 使用Swagger支持授权认证

    园子里已经有很多.NET Core 集成Swagger的文章,但对于使用授权的介绍蛮少的. public static class SwaggerServiceExtensions { public ...

  3. oracle中导出sql的几个常见词语的意思

    set feedback off不显示反馈信息  “1行已插入”,大量数据装入时,显示这个也是很浪费资源和时间的. set define off 如果你某个字段里面有&字符,插入数据会出错,设 ...

  4. codeforces 706C C. Hard problem(dp)

    题目链接: C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. 「P4994」「洛谷11月月赛」 终于结束的起点(枚举

    题目背景 终于结束的起点终于写下句点终于我们告别终于我们又回到原点…… 一个个 OIer 的竞赛生涯总是从一场 NOIp 开始,大多也在一场 NOIp 中结束,好似一次次轮回在不断上演.如果这次 NO ...

  6. 【Opencv】直方图函数 calchist()

    calchist函数需要包含头文件 #include <opencv2/imgproc/imgproc.hpp> 函数声明(三个重载 calchist函数): //! computes t ...

  7. poj3254二进制放牛——状态压缩DP

    题目:http://poj.org/problem?id=3254 利用二进制压缩状态,每一个整数代表一行的01情况: 注意预处理出二进制表示下没有两个1相邻的数的方法,我的方法(不知为何)错了,看到 ...

  8. stm32之入门知识

    一.stm32最小系统 stm32最小系统组成如下(除了stm32芯片外): 1.电源模块,3.3V电源,需要用稳压器件,有时要用感容网络产生stm32所使用的模拟电源. 2.时钟模块,有源或者无源晶 ...

  9. ACM-ICPC2018南京网络赛 AC Challenge(一维状压dp)

    AC Challenge 30.04% 1000ms 128536K   Dlsj is competing in a contest with n (0 < n \le 20)n(0<n ...

  10. 牛客多校3 C-Shuffle Cards(rope大法解决数组分块)

    Shuffle Cards 链接:https://www.nowcoder.com/acm/contest/141/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26 ...