C++-POJ1018-Communication System
贪心算法:先排序,再枚举最小带宽(B),每次更新当前最小花费(P)和以及答案(ans)
#include <cstdio>
#include <algorithm>
using namespace std; struct data {int b,p;} a[][];
int m[],B[]; bool cmp(const data &A,const data &B) {
if(A.b==B.b)return A.p > B.p;
return A.b < B.b;
} int main() {
int t,n;
for(scanf("%d",&t);t--;) {
scanf("%d",&n);
int i_B=;
for(int i=; i<=n; i++) {
scanf("%d",&m[i]);
for(int j=; j<=m[i]; j++) {
scanf("%d%d",&a[i][j].b,&a[i][j].p);
B[++i_B]=a[i][j].b;
}
sort(a[i]+,a[i]+m[i]+,cmp);
}
sort(B+,B+i_B+);
double ans=;bool flag;
for(int i=; i<=i_B; i++) { //枚举B的值
if(B[i]==B[i+] && i<i_B) continue;//剪枝
int sum_p=,min_p;
for(int j=; j<=n; j++) {
flag=true,min_p=;
for(int k=; k<=m[j]; k++)
if(a[j][k].b>=B[i] && a[j][k].p<min_p)
min_p=a[j][k].p,flag=false;
if(flag) break;
sum_p+=min_p;
}
if(flag) break;
ans=max(ans,(double)B[i]/sum_p);
}
printf("%.3f\n",ans);
}
return ;
}
C++-POJ1018-Communication System的更多相关文章
- POJ1018 Communication System
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26738 Accepted: 9546 Description We ...
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- 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 ...
- F - Communication System
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The 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: 22380 Accepted: ...
- Communication System(动态规划)
个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...
随机推荐
- css样式-区域内文字不会被选中
要注意浏览器的兼容性: -webkit-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none;
- 题解【洛谷P3456】[POI2007]GRZ-Ridges and Valleys
题面 考虑 \(\text{Flood Fill}\). 每次在 \(\text{BFS}\) 扩展的过程中增加几个判断条件,记录山峰和山谷的个数即可. #include <bits/stdc+ ...
- weblogic的ssrf漏洞
前言 什么是ssrf SSRF(Server-Side Request Forgery:服务器端请求伪造) 是一种由攻击者构造形成由服务端发起请求的一个安全漏洞. 一般情况下,SSRF攻击的目标 ...
- IntelliJ IDEA实用插件推荐
IntelliJ在业界被公认为优秀的Java开发平台之一,在智能代码助手.代码自动提示.重构.J2EE支持.代码审查. 创新的GUI设计等方面表现突出,并支持基于Android平台的程序开发.通过插件 ...
- LaTeX技巧008:如何给文字添加阴影效果?
大家可以使用这个包:shadowtext宏包
- 计算器程序编写_python
一.计算一串字符串的最终值,相当于eval函数功能: #!/usr/bin/env python # _*_ coding:utf-8 _*_ #Author:chenxz import re def ...
- 改变容器Size后,刷新地图大小。
You need to call the API to update map size. http://dev.openlayers.org/docs/files/OpenLayers/Map-js. ...
- 互联网的“ip分组交换技术”
(1)从名字分析 从“ip分组交换”这个名字中,我们看看涉及哪些事情. 1)交换 主要涉及两类交换. · 交换机:负责网内部数据交换 · 路由器:负责网间的数据交换. ip分组交换技术的核心就是路由器 ...
- TAB_JG_COMMAND_SERVERINFO
简介 存储设备基本信息 表结构
- 番外:可刷新PDB的管理操作(如何切换PDB Switching Over)
基于版本:19c (12.2.0.3) AskScuti 主题:可刷新PDB如何进行切换操作 内容说明:本篇延续如何克隆可刷新的PDB(Refreshable PDB)一文,进行切换实验. 具体请参考 ...