贪心,优先队列。

将$s$按照从小到大的顺序扔进优先队列。从小的开始与电脑配对,如果找不到合适的电脑,那么再变小一次,直到找到与之配对的电脑或者作废。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} int n,m;
int p[],s[],cnt[]; int h[],nx[]; int c,u;
int a[],b[],r[]; struct X
{
int s,id;
X(int S,int ID)
{
s=S;
id=ID;
}
bool operator < (const X &a) const {
return s>a.s;
}
};
priority_queue<X>q; int Z(int x)
{
int L=,R=n,res=-;
while(L<=R)
{
int mid=(L+R)/;
if(r[mid]>x) R=mid-;
else if(r[mid]==x) R=mid-,res=mid;
else L=mid+;
}
return res;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) { scanf("%d",&p[i]); r[i]=p[i]; }
sort(r+,r++n); memset(h,-,sizeof h); for(int i=;i<=n;i++)
{
int pp=Z(p[i]);
nx[i]=h[pp], h[pp]=i;
} for(int i=;i<=m;i++) { scanf("%d",&s[i]); q.push(X(s[i],i)); } while(!q.empty())
{
X top = q.top(); q.pop();
while()
{
int pp=Z(top.s);
if(top.s==&&pp==-) break;
if(top.s==&&pp!=-&&h[pp]==-) break;
if(pp!=-&&h[pp]!=-)
{
c++; u=u+cnt[top.id];
a[top.id]=cnt[top.id];
b[h[pp]]=top.id;
h[pp]=nx[h[pp]];
break;
}
else
{
if(top.s%==) top.s=top.s/;
else top.s=top.s/+;
cnt[top.id]++;
}
}
} printf("%d %d\n",c,u);
for(int i=;i<=m;i++) printf("%d ",a[i]); cout<<endl;
for(int i=;i<=n;i++) printf("%d ",b[i]); cout<<endl; return ;
}

最新文章

  1. 注意:DateTimePicker.Text不靠谱
  2. BizTalk动手实验(四)Schema开发测试
  3. Thinking in Java——笔记(6)
  4. .net core 使用Autofac依赖注入
  5. Codeforces Round #290 (Div. 2) C. Fox And Names dfs
  6. Verilog中锁存器与多路选择器
  7. 使用Travis CI自动部署Hexo到GitHub
  8. matlab中 mcc、mbuild和mex命令详解
  9. PMM Client 安装异常报错
  10. Jmeter性能测试之Monitor监控(四)
  11. java操作Maven
  12. Linux开发工具_yum使用
  13. baidu-map
  14. .net MVC简洁的登录页面
  15. 更新合并数组的es6方法
  16. JavaScript之BOM对象
  17. 【LeetCode】Number of Islands
  18. Linux Web服务器网站故障分析常用的命令
  19. quartz 的简单使用
  20. Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏

热门文章

  1. mysql 压缩包免安装版 安转步骤
  2. 2015/9/5 Python基础(9):条件和循环
  3. u3d局域网游戏网络(c# socket select 模型)
  4. python初步学习-pycharm使用 (二)
  5. 常见网络命令之traceroute命令一起其他常用命令
  6. 我用.htaccess做了些什么?
  7. 转 白话解析:一致性哈希算法 consistent hashing
  8. Sql Server 2014/2012/2008/2005 数据库还原出现 3154错误的解决办法
  9. 读取BMP图像size的时候与操作和左移的原因
  10. 1002: 当不成勇者的Water只好去下棋了---课程作业---图的填色