【贪心】Communication System POJ 1018
题目链接:http://poj.org/problem?id=1018
题目大意:有n种通讯设备,每种有mi个制造商,bi、pi分别是带宽和价格。在每种设备中选一个制造商让最小带宽B与总价格P的比值B/P最大。
解法是枚举最小带宽B,每种设备在带宽大于B的制造商中找价格最小的,最后取比值最大的。
详见代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,d[105][105],p[105][105],Min,Max,t;
int main()
{
scanf("%d",&t);
while(t--)
{
memset(d,0,sizeof d);
memset(p,0,sizeof p);
Min=0xffff;
Max=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&d[i][0]);
for(int j=1;j<=d[i][0];j++)
{
scanf("%d%d",&d[i][j],&p[i][j]);
Max=Max<d[i][j]?d[i][j]:Max;
Min=Min>d[i][j]?d[i][j]:Min;
}
}
double ans=0;
for(int i=Min;i<=Max;i++)
{
int sum=0;
for(int j=1;j<=n;j++){
int mx=0xffff;
for(int k=1;k<=d[j][0];k++)
if(d[j][k]>=i&&mx>p[j][k])
mx=p[j][k];
sum+=mx;
}
if(ans<i*1.0/sum) ans=i*1.0/sum;
}
printf("%.3lf\n",ans);
}
}
【贪心】Communication System POJ 1018的更多相关文章
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- poj 1018 Communication System (枚举)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22380 Accepted: ...
- poj 1018(枚举+贪心)
通讯系统 We have received an o ...
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- 2017ecjtu-summer training #11 POJ 1018
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29218 Accepted: ...
随机推荐
- 【转帖】MIPS构架之:我和龙芯有个约会
MIPS构架之:我和龙芯有个约会 https://www.eefocus.com/mcu-dsp/364490 <处理器史话>之十二 2016-06-24 12:21 作者:付丽华预计 1 ...
- css3 网页图片轮播的实现
.lunbo{ height: 640px; width: 100%; background-position: -280px; margin-top: 103px; -webkit-animatio ...
- API总结
1. 什么是Webservice WebService就是一个应用程序向外界暴露出一个能通过Web进行调用的API,也就是说能用编程的方法通过 Web 来调用这个应用程序.我们把调用这个WebServ ...
- M-SOLUTIONS Programming Contest
A.(n-2)*180 #include<cstdio> #include<cstring> #include<iostream> #include<algo ...
- backpropagation algorithm
搞卷积神经网络的时候突然发现自己不清楚神经网络怎么训练了,满脸黑线,借此机会复习一下把. 首先放一位知乎大佬的解释.https://www.zhihu.com/question/27239198?rf ...
- 进入恢复模式(Recovery HD)
进入恢复模式(Recovery HD) 1,选中要启动的虚拟机,随后点击VM菜单的启动按钮后面向下箭头,随后点击菜单项”打开电源时进入固件“. 2,在虚拟机里面,用上下键移动到”Enter setup ...
- openwrt luci web分析
openwrt luci web分析 来源 https://www.jianshu.com/p/596485f95cf2 www/cbi-bin/luci #!/usr/bin/lua --cgi的执 ...
- python逻辑编程之kanren
https://github.com/logpy/logpy https://pypi.org/project/kanren/ https://www.yiibai.com/ai_with_pytho ...
- 不能在本机启动SQL Server服务错误代码126(要在协议里面禁用所有别的VIA,是怎么回事?)
在启动数据库sql服务的时候提示[Windows 不能在 本地计算机 启动 SQL Server . 有关更多信息,查阅系统事件日志.如果这是非 Microsoft 服务,请与服务厂商联系,并参考特定 ...
- GitHub上传文件夹
1.输入自己的用户名和邮箱 为注册GitHub账号时所用的用户名和邮箱;我的用户名为“1997ST2016”,邮箱为“1324971964@qq.com ”. $ git config --globa ...