UVA 1456 六 Cellular Network
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
A cellular network is a radio network made up of a number of cells each served by a base station located in the cell. The base station receives call signals from mobile users (mobiles) in the cell it serves, which then connects the calls to the wired land-line telephone network. When a call is requested to connect to a mobile, the cellular network must know in which cell the mobile is located so that the call is routed to the base station of the cell appropriately.
Mobiles move from once cell to another in a cellular network. Whenever a mobile reports its new cell as it crosses boundaries of cells, the cellular network would know its exact cell at any time and finding (paging) the mobile becomes a trivial task. But it is usually infeasible for a mobile to report its new location each time it enters a new cell because of the insufficiencies of resources such as the radio bandwidth. But normally at the time of a call arrival, the cellular network knows a limited number of cells where the mobile is located. In this situation, a lot of paging strategies are developed to locate a mobile efficiently. The ultimate goal of paging strategies is to minimize both the time delay and cost of paging until the mobile is found.
Now we define our problem formally. The location area is the set of n cells C = {c1, c2,..., cn} such that the mobile is guaranteed to be in one of these cells at the time of a call arrival. Suppose that it is possible to page any subset of these n cells in a unit of time (paging rounds) and find out if the mobile is located in one of the cells paged. The fastest strategy to find the cell where the mobile is located is to page all the n cells in the first and only round. However this strategy uses a lot of wireless bandwidth.
In many cases, the cellular network knows about the whereabouts of the mobile. This knowledge can be modeled with n probability values, where the probability of the mobile being present in a cell can be estimated for each of these n cells at the time of a call arrival. Let pi be the probability that the mobile is located at the cell ci and all the probabilities are independent. A sequential paging strategy is to page the cells sequentially in n paging rounds terminating once the mobile is found. Then the average cost of paging (number of cells paged), , and the average paging delay (number of paging rounds) in locating the mobile,, can be expressed as follows:
The parallel paging strategy is to page the cells in a collection of cells simultaneously. Sequential paging strategy has lower paging cost than parallel paging strategy, but at the expense of larger paging delay. The method of parallel paging is to partition the cells in a location area into a series of indexed groups referred to as paging zones. Let Z1, Z2,..., Zw be the partition of the location area C (i.e., a partition of C into w groups), where each Zi is non-empty and corresponds to a distinct paging zone. When a call arrives for a mobile, the cells in the first paging zone Z1 are paged simultaneously in the first round and then if the mobile is not found in the first round of paging, all the cells in the second paging zone Z2 are paged, and so on. Let the number of cells in the paging zone Zi be denoted by ni = | Zi|, and let be the corresponding zone probabilities of the users in the paging zone Zi, where = pj. Then the average cost of paging (number of cells paged), , and the average paging delay (number of paging rounds) in locating the mobile, D, can be expressed as follows:
In parallel paging strategy, there is a tradeoff between bandwidth for time. For example, we increases the number of paging zones, then the paging cost could be decreased. If we decrease the number of paging zones, then the paging cost could be increased. Furthermore, for a fixed number w of paging zones, the paging cost could be different to the strategies how the cells in location area are partitioned.
For example, there are n = 5 cells in a location area C = {c1, c2,..., c5} and the probability of each cells in C are as follows:
ci | c1 | c2 | c3 | c4 | c5 |
pi | 0.3 | 0.05 | 0.1 | 0.3 | 0.25 |
If the cells in C are partitioned into two paging zones Z1 = {c1, c2, c3}, Z2 = {c4, c5}, the average cost of paging, , and the average paging delay in locating the mobile, , are:
= n1 + (n1 + n2) = 3(0.3 + 0.05 + 0.1) + (3 + 2)(0.3 + 0.25) = 3 x 0.45 + 5 x 0.55 = 4.1
= 1 +2 = 1(0.3 + 0.05 + 0.1) + 2(0.3 + 0.25) = 1 x 0.45 + 2 x 0.55 = 1.55
If the cells in C are partitioned into two paging zones Z1 = {c1, c4}, Z2 = {c2, c3, c5}, the average cost of paging, , and the average paging delay in locating the mobile, , are:
= n1 + (n1 + n2) = 2(0.3 + 0.3) + (3 + 2)(0.05 + 0.1 + 0.25) = 2 x 0.6 + 5 x 0.4 = 3.2
= 1 +2 = 1(0.3 + 0.3) + 2(0.05 + 0.1 + 0.25) = 1 x 0.6 + 2 x 0.4 = 1.4
Given the number of cells in a location area C, the probabilities of each cells that a mobile is located at the cell, and the fixed number w of paging zones, write a program to partition the cells in C into w paging zones such that the average cost of paging to find the location of the mobile is minimized.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test cases Tis given in the first line of the input. Each test case consists of two lines. The first line of each test case contains two integers. The first integer, n, is the number of cells in a location area, and the second integer, w, is the number of paging zones, where 1wn100. The second line of each test case contains nintegers u1, u2,..., un, where the probability pi for each cell ci in C is pi = ui/(u1 + u2 + ... + un). All integers in the second line are between 1 and 10,000.
Output
Your program is to write to standard output. Print exactly one line for each test case. The line should contain the minimum average cost of paging to find the location of the mobile. The output should have a precision of exactly 4 digits after decimal point. You may round to the 4 digits after decimal point or round off at the 4-th digit after decimal point.
The following shows sample input and output for two test cases.
Sample Input
2
5 2
30 5 10 30 25
5 5
30 5 10 30 25
Sample Output
3.2000
2.3000
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; bool cmp(double x,double y)
{
return x>y;
} const double inf=0x3f3f3f3f; int main()
{
int i,j,k;
int n,w;
int T;
double dp[][];
double a[],sum[];
double s;
scanf("%d",&T);
while(T--)
{
s=;
scanf("%d %d",&n,&w);
for(i=;i<=n;i++)
{
scanf("%lf",&a[i]);
s=s+a[i];
}
sort(a+,a+n+,cmp);
sum[]=;
for(i=;i<=n;i++)
{
sum[i]=sum[i-]+a[i];
} dp[][]=;
for(i=;i<=n;i++)
dp[i][]=inf; for(i=;i<=n;i++)
{
for(j=;j<=i && j<=w;j++)
{
dp[i][j]=inf;
for(k=;k<i;k++)
{
if(j-<=k)
dp[i][j]=min(dp[i][j],dp[k][j-]+i*(sum[i]-sum[k])/s);
}
}
} printf("%.4lf\n",dp[n][w]);
}
return ;
}
UVA 1456 六 Cellular Network的更多相关文章
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- Codeforces Educational Codeforces Round 15 C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- cf702C Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15_C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- codeforces 702C C. Cellular Network(水题)
题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- 深度学习(二十六)Network In Network学习笔记
深度学习(二十六)Network In Network学习笔记 Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/deta ...
- CodeForce-702C Cellular Network(查找)
Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 ...
随机推荐
- 夺命雷公狗—angularjs—18—angularjs的事件
对于一款前端框架,提起事件,很容易让人联想到DOM事件,比如说鼠标点击以及页面滚动等.但是我们这里说的angular中的事件和DOM事件并不是一个东西. 事件的发布 我们可以通过 $emit() 以及 ...
- 夺命雷公狗---DEDECMS----8dedecms干掉首页和-文档页-栏目页的页面的广告
我们首先来将首页生成静态页面,如下图所示: 成功后,如下显示: 如果成功后则在文件夹下多了一个index.html的文件.. 我们的首页静态页面是通过模版文件生成,所以我们只需要把模版文件的广告标签删 ...
- lower power的physical library
在一个cell library中,比较重要的是cell height,cell height由tracks来决定,track表示一个metal线的pitch. 一个cell通常被做成一定数量的trac ...
- IE已经被抛弃,但是不能遗忘
虽然IE的兼容问题,在我写这篇文章的时候基本已经被抛弃了,但是我觉得还是应该了解一下最基本的解决办法. 就像中国的历史已经过去,但是我们不能忘记一样的. 逐个版本解决法 .bb{ background ...
- 如何写一个c++插件化系统
1.为什么需要插件化系统 “编程就是构建一个一个自己的小积木, 然后用自己的小积木搭建大系统”. 但是程序还是会比积木要复杂, 我们的系统必须要保证小积木能搭建出大的系统(必须能被组合),有必须能使各 ...
- 什么是BI(Business Intelligence)【转】
谈谈对BI的理解,从BI的定义.基本技术.专业名词.实例应用及扩展等方面进行重新描述,巩固对BI的理解. 一.BI的定义 BI是Business Intelligence的英文缩写,中文解释为商务智能 ...
- WM_SETFOCUS和WM_KILLFOCUS、WM_GETDLGCODE、CM_ENTER...
procedure WMSetFocus (var Message: TWMSetFocus); message WM_SETFOCUS; //获得焦点 procedure WMKillFocus ( ...
- python使用装饰器捕获异常
可以编写一个通用的捕获异常的装饰器, 当程序发生异常时可以继续执行后续动作. 尤其适合于使用大量断言的验证性程序. 装饰器的实现原理使用了回调技术. 如下所示, robust 是一个装饰器. 当在普通 ...
- history and its relevant variables in Linux/GNU and Mac OS history命令以及相关环境变量
对于Terminalor们,history命令并不陌生,什么!n, !!更是很常用的,而且您在命令行敲的cmds是默认保存在/home/$USER/.bash_history(linux) /User ...
- ecshop增加pc扫描二维码微信支付功能代码
ecshop开发网站,如果没有手机版,又想通过微信支付,可以加入pc二维码扫描微信支付功能 工具/原料 ecshop商城系统,phpqrcode,WxPayPubHelper 公众号已申请微信支付 方 ...