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 ...
随机推荐
- [LeetCode] 17. Letter Combinations of a Phone Number ☆☆
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- ZooKeeper屏障和队列的指南(七)
引言 在这个指南中,使用展示了使用ZooKeeper实现的屏障和生产-消费队列.我们分别称这些类为Barrier和Queue.这些例子假定你至少有一个运行的ZooKeeper服务. 两个原语都使用下面 ...
- Lucene4.6至 Lucene6.6的每个迭代对API的改动
由于项目需求,需要将Lucene4.6升级到Lucene6.6,因此我对这之间的所有重要的API改动做了搜集:特别重要的改变加粗显示. Lucene4.7改动: LUCENE-5405: Make S ...
- opencv在property panel中新建一行
是用cv2.QT_NEW_BUTTONBAR和button type通过竖线结合可以在创建一行,如下 cv2.createButton("CV_RADIOBOX2", redraw ...
- 【BZOJ1879】【SDOI2009】Bill的挑战 [状压DP]
Bill的挑战 Time Limit: 4 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Input 第一行:一个整数T, ...
- 【BZOJ】2982 combination
[算法]组合数取模——lucas定理 #include<cstdio> #include<algorithm> #include<cstring> using na ...
- MongoDB安装配置及使用
1.安装配置:https://www.cnblogs.com/ymwangel/p/5859453.html 2.使用 from pymongo import MongoClient #连接 conn ...
- bzoj 1030 ac自动机
比较容易看出来先建立ac自动机,然后在自动机上做DP,设w[0..1][i][j]为当前不包括/包括字典中的字符串,当前在自动机中走到第i个节点,完成的文本的长度为j的方案数,那么比较容易的转移w[i ...
- for in、each; for 、forEach、map
1.jQuery.each(object, [callback]) 用于例遍任何对象.回调函数拥有两个参数:第一个为对象的成员或数组的索引,第二个为对应变量或内容.如果需要退出 each 循环可使回调 ...
- Linking code for an enhanced application binary interface (ABI) with decode time instruction optimization
A code sequence made up multiple instructions and specifying an offset from a base address is identi ...