CodeForces 732E Sockets
贪心,优先队列。
将$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的更多相关文章
- 【20.69%】【codeforces 732E】Sockets
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces 732E(贪心)
题目链接:http://codeforces.com/contest/732/problem/E 题意:有n台计算机,m个插座,每台计算机有一个值a[i],每个插座有一个值b[i],每个插座最多只能对 ...
- Codeforces 732e [贪心][stl乱搞]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...
- Codeforces Round #377 (Div. 2) E. Sockets
http://codeforces.com/contest/732/problem/E 题目说得很清楚,每个电脑去插一个插座,然后要刚好的,电脑的power和sockets的值相同才行. 如果不同,还 ...
- 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 ...
- Sockets CF732E set map
题目:http://codeforces.com/problemset/problem/732/E 题目大意: 有n台电脑(computer)和m个插座(socket),两者均有一个power值,分别 ...
- HTML5权威指南--Web Storage,本地数据库,本地缓存API,Web Sockets API,Geolocation API(简要学习笔记二)
1.Web Storage HTML5除了Canvas元素之外,还有一个非常重要的功能那就是客户端本地保存数据的Web Storage功能. 以前都是用cookies保存用户名等简单信息. 但是c ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- 【设计模式】 模式PK:门面模式VS中介者模式
1.概述 门面模式为复杂的子系统提供一个统一的访问界面,它定义的是一个高层接口,该接口使得子系统更加容易使用,避免外部模块深入到子系统内部而产生与子系统内部细节耦合的问题.中介者模式使用一个中介对象来 ...
- 删除windows上特定目录下以*.rar后缀名的python脚本
import os,fnmatch,datetime,time def all_files(root,pattern='*',single_level=False,yield_folders=Fals ...
- SQL Server Compact/SQLite Toolbox
如果你的vs2013 无法打开 .sdf 数据库文件. 那么 SQL Server Compact/SQLite Toolbox,可以帮助你. 下载安装后, vs2013->tools-> ...
- POJ 2533 Longest Ordered Subsequence LIS O(n*log(n))
题目链接 最长上升子序列O(n*log(n))的做法,只能用于求长度不能求序列. #include <iostream> #include <algorithm> using ...
- 老生常谈-Activity(山东数漫江湖)
对于activity的七个声生命周期回调,总是被大家翻来覆去的说,甚至说的都有些厌烦了,这部分知识虽然基础但也很重要,谁都不想在面试的时候只说出个一知半解,下面的分析是对阅读<安卓开发艺术探索& ...
- [2009国家集训队]小Z的袜子(hose)(BZOJ2038+莫队入门题)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2038 题目: 题意:中文题意,大家都懂. 思路:莫队入门题.不过由于要去概率,所以我们假 ...
- select下拉箭头改变,兼容ie8/9
各个浏览器下select默认的下拉箭头差别较大,通常会清除默认样式,重新设计 <html> <head> <meta charset="utf-8"& ...
- nodejs安装express以后,使用express显示不是内部或外部命令
1.问题描述 在命令窗口通过npm install -g express 安装express以后,通过express -e express新建工程失败,提示express不是内部或外部命令 2.解决方 ...
- Linux中source命令的用法
source命令: source命令也称为“点命令”,也就是一个点符号(.).source命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录.因为linux所有的操作都会变成文 ...
- vmware安装ubuntu " Intel VT-x 处于禁用状态"
vmware安装ubuntu " Intel VT-x 处于禁用状态" http://jingyan.baidu.com/article/fc07f98976710e12ffe51 ...