贪心,优先队列。

将$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 ;
}

CodeForces 732E Sockets的更多相关文章

  1. 【20.69%】【codeforces 732E】Sockets

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. codeforces 732E(贪心)

    题目链接:http://codeforces.com/contest/732/problem/E 题意:有n台计算机,m个插座,每台计算机有一个值a[i],每个插座有一个值b[i],每个插座最多只能对 ...

  3. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

  4. Codeforces Round #377 (Div. 2) E. Sockets

    http://codeforces.com/contest/732/problem/E 题目说得很清楚,每个电脑去插一个插座,然后要刚好的,电脑的power和sockets的值相同才行. 如果不同,还 ...

  5. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem I. Plugs and Sockets 费用流

    Problem I. Plugs and Sockets 题目连接: http://www.codeforces.com/gym/100253 Description The Berland Regi ...

  6. Sockets CF732E set map

    题目:http://codeforces.com/problemset/problem/732/E 题目大意: 有n台电脑(computer)和m个插座(socket),两者均有一个power值,分别 ...

  7. HTML5权威指南--Web Storage,本地数据库,本地缓存API,Web Sockets API,Geolocation API(简要学习笔记二)

    1.Web Storage HTML5除了Canvas元素之外,还有一个非常重要的功能那就是客户端本地保存数据的Web Storage功能. 以前都是用cookies保存用户名等简单信息.   但是c ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. ZooKeeper内部构件

    引言 这个文档包含关于ZK内部工作的信息.目前为止,它讨论了这些主题: 原子广播 日志 原子传播 ZK的核心是一个原子的通信系统,它使所有的服务端保持同步. 保证.属性和定义 通过使用ZooKeepe ...

  2. OScached页面缓存的概念和安装

    一.基本概述 OSCache标记库由OpenSymphony设计,它是一种开创性的JSP定制标记应用,提供了在现有JSP页面之内实现快速内存缓冲的功能.OSCache是个一个广泛采用的高性能的J2EE ...

  3. 面试精选之Promise

    常见Promise面试题 我们看一些 Promise 的常见面试问法,由浅至深. 1.了解 Promise 吗? 2.Promise 解决的痛点是什么? 3.Promise 解决的痛点还有其他方法可以 ...

  4. Spring与MyBatis的整合(山东数漫江湖)

    首先看一下项目结构图: 具体步骤如下: 1.建立JDBC属性文件 jdbc.properties (文件编码修改为 utf-8 ) driver=com.mysql.jdbc.Driver url=j ...

  5. Runas replacement tool

    1. RunAsSpc Runas 无法在脚本中输入密码,可以使用RunAsSpc替代. RunAsSpc = runas + password + encryption https://robotr ...

  6. 如何用CMD开启3389与查看3389端口

    开启 REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections / ...

  7. Java 关于微信公众号支付总结附代码

    很多朋友第一次做微信支付的时候都有蒙,但当你完整的做一次就会发现其实并没有那么难 业务流程和应用场景官网有详细的说明:https://pay.weixin.qq.com/wiki/doc/api/js ...

  8. Python标准库笔记(4) — collections模块

    这个模块提供几个非常有用的Python容器类型 1.容器 名称 功能描述 OrderedDict 保持了key插入顺序的dict namedtuple 生成可以使用名字来访问元素内容的tuple子类 ...

  9. Vue组件-使用插槽分发内容

    在使用组件时,我们常常要像这样组合它们: <app> <app-header></app-header> <app-footer></app-fo ...

  10. 跟踪内核启动过程CONFIG_DEBUG_LL【转自】

    转自:http://bbs.chinaunix.net/thread-3642079-1-1.html 最近在调试Linux内核,跟踪启动过程.发现在没有turn on mmu之前,可以使用物理地址, ...