codeforces732E Sockets(数据结构+贪心+思维)
来源:互联网 发布:刘飞儿faye知乎 编辑:程序博客网 时间:2024/05/16 06:04
题意
思路
先比较有无相同的,有则匹配,然后对s序列除2向上取整,再比较,一直循环,循环31次。我用的multimap。
代码
/* ********************************Author : danmuCreated Time : 2016年11月10日 星期四 12时11分27秒File Name : a.cpp******************************** */#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <iomanip>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>#include <list>#include <map>#include <set>#define rep(i,x,y) for(int i=x;i<=y;++i)#define _rep(i,x,y) for(int i=x;i>=y;--i)#define CL(S,x) memset(S,x,sizeof(S))#define CP (S1,S2) memcpy(S1,S2,sizeof(S2))#define ALL(x,S) for(x=S.begin();x!=S.end();++x)#define ULL unsigned long long#define PI 3.1415926535#define INF 0x3f3f3f3f#define LL long longconst int maxn = 2e5;const int mod = 1e9 + 7;const double eps = 1e-8;using namespace std;int n,m,c,u;int s[maxn+5];multimap<int,int> p;int ansa[maxn+5],ansb[maxn+5];int main(){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int tmp; memset(ansa,-1,sizeof ansa); scanf("%d%d",&n,&m); for(int i=1;i<=n;++i){ scanf("%d",&tmp); p.insert(make_pair(tmp,i)); } for(int i=1;i<=m;++i){ scanf("%d",s+i); } for(int i=0;i<=30;++i){ for(int j=1;j<=m;++j){ if(ansa[j]==-1){ multimap<int,int>::iterator it=p.find(s[j]); if(it!=p.end()){ ansa[j]=i; ansb[it->second]=j; ++c; u+=i; p.erase(it); } } } for(int j=1;j<=m;++j) s[j]=s[j]/2+(s[j]&1?1:0); } printf("%d %d\n",c,u); for(int i=1;i<=m;++i){ printf("%d%c",ansa[i]==-1?0:ansa[i],i==m?'\n':' '); } for(int i=1;i<=n;++i){ printf("%d%c",ansb[i],i==n?'\n':' '); } return 0;}
总结
满足两个条件的最优,可以在保证某个条件成立的前提下,取另一个条件的最优。
0 0
- codeforces732E Sockets(数据结构+贪心+思维)
- codeforces732E Sockets(贪心)
- Codeforces 732E Sockets【贪心】
- Gym 100886J Sockets(二分+贪心)
- 贪心,优化(Sockets,cf 732e)
- codeforce 732e Sockets (贪心)
- CodeForces 732E Sockets 【贪心】【STL】
- CodeForces 732 E.Sockets(贪心)
- UVA 10970 (思维,贪心)
- poj 2393 贪心 思维
- Equal (贪心,思维)
- Crane ----思维+贪心
- 贪心+思维策略
- sockets
- sockets
- Sockets
- Sockets
- hdu 4898 LCP+贪心思维
- luence的java工具类,通用类型解析,支持数据库
- uva10795 A Different Task
- hdu 3094——A tree game
- 2.docker学习笔记:制作docker镜像
- Spring Boot学习第三篇:Spring Boot整合Mybatis、和其他
- codeforces732E Sockets(数据结构+贪心+思维)
- STM32 USB 大容量存储器Mass Storage工程的讲解
- 字体下载
- 清理Windows.edb文件释放C盘空间
- orcle同义词的创建
- Now直播应用的后台服务器性能测试实践
- 温习小知识---typedef
- 【模拟】Luogu P1518 两只塔姆沃思牛(The Tamworth Two)
- hbase行键过滤器RowFilter