Sockets
2 seconds
256 megabytes
standard input
standard output
The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy preparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.
There are n computers for participants, the i-th of which has power equal to positive integer pi. At the same time there are m sockets available, the j-th of which has power euqal to positive integer sj. It is possible to connect the i-th computer to the j-th socket if and only if their powers are the same: pi = sj. It is allowed to connect no more than one computer to one socket. Thus, if the powers of all computers and sockets are distinct, then no computer can be connected to any of the sockets.
In order to fix the situation professor Puch Williams urgently ordered a wagon of adapters — power splitters. Each adapter has one plug and one socket with a voltage divider between them. After plugging an adapter to a socket with power x, the power on the adapter's socket becomes equal to
, it means that it is equal to the socket's power divided by two with rounding up, for example
and
.
Each adapter can be used only once. It is possible to connect several adapters in a chain plugging the first to a socket. For example, if two adapters are plugged one after enother to a socket with power 10, it becomes possible to connect one computer with power 3 to this socket.
The organizers should install adapters so that it will be possible to supply with electricity the maximum number of computers c at the same time. If there are several possible connection configurations, they want to find the one that uses the minimum number of adapters u to connect c computers.
Help organizers calculate the maximum number of connected computers c and the minimum number of adapters u needed for this.
The wagon of adapters contains enough of them to do the task. It is guaranteed that it's possible to connect at least one computer.
The first line contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of computers and the number of sockets.
The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 109) — the powers of the computers.
The third line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 109) — the power of the sockets.
In the first line print two numbers c and u — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connect c computers.
In the second line print m integers a1, a2, ..., am (0 ≤ ai ≤ 109), where ai equals the number of adapters orginizers need to plug into the i-th socket. The sum of all ai should be equal to u.
In third line print n integers b1, b2, ..., bn (0 ≤ bi ≤ m), where the bj-th equals the number of the socket which the j-th computer should be connected to. bj = 0 means that the j-th computer should not be connected to any socket. All bj that are different from 0 should be distinct. The power of the j-th computer should be equal to the power of the socket bj after plugging in abj adapters. The number of non-zero bj should be equal to c.
If there are multiple answers, print any of them.
2 2
1 1
2 2
2 2
1 1
1 2
2 1
2 100
99
1 6
6
1 0
分析:按转换器个数排序模拟即可,能插则插,否则/2上取整放回去;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,p[maxn],s[maxn],vis[maxn],vis1[maxn],used[maxn],c,u;
queue<pii>pq;
set<pii>q;
int main()
{
int i,j;
scanf("%d%d",&n,&m);
rep(i,,n)scanf("%d",&p[i]),q.insert(mp(p[i],i));
rep(i,,m)scanf("%d",&s[i]),pq.push(mp(s[i],i));
while(!pq.empty())
{
pii x=pq.front();
pq.pop();
bool flag=false;
auto it=q.lower_bound(mp(x.fi,));
if(it!=q.end()&&it->fi==x.fi)
{
vis[it->se]=x.se;
vis1[x.se]=it->se;
flag=true;
q.erase(it);
}
if(!flag)
{
if(x.fi!=)
{
if(x.fi&)x.fi++;
x.fi>>=;
used[x.se]++;
pq.push(mp(x.fi,x.se));
}
}
}
rep(i,,n)if(vis[i])c++;
rep(i,,m)if(vis1[i])u+=used[i];
printf("%d %d\n",c,u);
rep(i,,m)
{
if(vis1[i])printf("%d ",used[i]);
else printf("0 ");
}
printf("\n");
rep(i,,n)printf("%d ",vis[i]);
printf("\n");
//system("Pause");
return ;
}
Sockets的更多相关文章
- HTML5权威指南--Web Storage,本地数据库,本地缓存API,Web Sockets API,Geolocation API(简要学习笔记二)
1.Web Storage HTML5除了Canvas元素之外,还有一个非常重要的功能那就是客户端本地保存数据的Web Storage功能. 以前都是用cookies保存用户名等简单信息. 但是c ...
- Net.Sockets
#region 程序集 System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:\Program ...
- 联不上网 Unable to initialize Windows Sockets interface. General failure.
电脑莫名联不上网 Unable to initialize Windows Sockets interface. General failure. Unable to initialize the W ...
- Unrecognized Windows Sockets error: 0: JVM_Bind 异常怎么办
Unrecognized Windows Sockets error: 0: JVM_Bind 异常解决办法 java.net.SocketException: Unrecognized Window ...
- System.Net.Sockets.Socket SendAsync System.ObjectDisposedException: Cannot access a disposed object.
发生未处理的域异常! System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net ...
- Socket Programming in C#--Multiple Sockets
Now lets say you have two sockets connecting to either two different servers or same server (which i ...
- ava.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind (解决思路)
当我们在启动tomcat服务的时候报错信息:java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bin 分析:从错 ...
- Unrecognized Windows Sockets error: 0: JVM_Bind
Unrecognized Windows Sockets error: 0: JVM_Bind [转帖]今天很是奇怪,在运行服务器端的时候,经常遇到这个异常: java.net.SocketExcep ...
- weblogic sockets 和 thread 问题解决
原创文章,转载须注明出处. 这个问题网上很多答案,可惜没一个能解决.后来发现是weblogic 必须适配JDK 版本. 一般会报这个错误,There are: 5 active sockets, bu ...
- socket.io问题,io.sockets.manager.rooms和io.sockets.clients('particular room')这两个函数怎么用?
为什么我用nodejs用这个两个函数获取都会出错呢?是不是socket的api改了?请问现在获取房间数和当前房间的客户怎么获取?什么函数?谢谢!!急求! 网友采纳 版本问题.io.socket ...
随机推荐
- Ubuntu 14.04 apt源更新
# 14.04 下进 my /etc/apt/sources.list /etc/apt/sources.bak vi /etc/apt/sources.list 从以下源中选择一个 源列表 Trus ...
- mybatis 查询语句(按条件查询)
<select id="getAllDitch" parameterType="xxx.xx.entity.CheckDitch" resultType= ...
- stl实现结构体排序关键语法要点(sort)
sort函数,调用时使用函数头: #include <algorithm> sort(begin,end);用来表示一个范围. int _tmain(int argc, _TCHAR* a ...
- libmad编译
patch -Np1 -i ../libmad-0.15.1b-fixes-1.patch && sed "s@AM_CONFIG_HEADER@AC_CONFIG_HEAD ...
- jQuery,使用on代替delegate,live 写法区别
早期对页面上后期加载的动态元素,赋事件或值的时候,是使用live的. 由于效率比较低(其实数据不多也感觉不出来),后面使用delegate委托来代替了,再后面,1.7以后使用on 来代替delega ...
- ORACLE小工具:存储过程清空所有表或使所有触发器失效
清空所有表: CREATE OR REPLACE PROCEDURE CLEAN_TABLES as v_tablename varchar2(256); cursor cur_tablename i ...
- GRPC: set up..
get the grpc source file.. git clone https://github.com/grpc/grpc git submodule update --init --recu ...
- U盘做svn版本控制
svn提供的访问方式有: file:///本地路径/to/svnrepo/ //访问本地磁盘 http://host/to/svnrepo/ //通过配置subversion的apache服务器的we ...
- mongodb 数据库导入.cvs文件时某些字段类型变成NumberLong的解决办法
在mongodb中导入数据时,会在数据库中生成字段记录为NumberLong的数据,可以使用以下方式将其转换为String db.Account.find().forEach( function(it ...
- leetcode83,删除有序链表中的重复元素
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...