UVA 1456 六 Cellular Network

Cellular Network

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status Practice UVA 1456

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 = {c1c2,..., 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:

(i x pi),(i x pi).

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 Z1Z2,..., 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:

 = (),(i x ).

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 = {c1c2,..., 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 = {c1c2c3}, Z2 = {c4c5}, 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 = {c1c4}, Z2 = {c2c3c5}, 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 u1u2,..., 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

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 bool cmp(double x,double y)
 7 {
 8     return x>y;
 9 }
10
11 const double inf=0x3f3f3f3f;
12
13 int main()
14 {
15     int i,j,k;
16     int n,w;
17     int T;
18     double dp[105][105];
19     double a[105],sum[105];
20     double s;
21     scanf("%d",&T);
22     while(T--)
23     {
24         s=0;
25         scanf("%d %d",&n,&w);
26         for(i=1;i<=n;i++)
27         {
28             scanf("%lf",&a[i]);
29             s=s+a[i];
30         }
31         sort(a+1,a+n+1,cmp);
32         sum[0]=0;
33         for(i=1;i<=n;i++)
34         {
35             sum[i]=sum[i-1]+a[i];
36         }
37
38         dp[0][0]=0;
39         for(i=1;i<=n;i++)
40             dp[i][0]=inf;
41
42         for(i=1;i<=n;i++)
43         {
44             for(j=1;j<=i && j<=w;j++)
45             {
46                 dp[i][j]=inf;
47                 for(k=0;k<i;k++)
48                 {
49                     if(j-1<=k)
50                         dp[i][j]=min(dp[i][j],dp[k][j-1]+i*(sum[i]-sum[k])/s);
51                 }
52             }
53         }
54
55         printf("%.4lf\n",dp[n][w]);
56     }
57     return 0;
58 }

时间: 2024-12-23 22:21:31

UVA 1456 六 Cellular Network的相关文章

uva live 4731 Cellular Network 线性dp

// uva live 4731 // // 状态很好想: // d(i,j)表示前i个网络分为j组所得到的数学期望的最小值 // 转移方程: // d(i,j) = min(d(k,j-1)+cost); // cost由题目给出的条件可知cost = (k+1...i)段的概率和 * i; // // 注意: // 1)肯定概率大的网络分在前面,这样在后面的话,这个大的概率出现在 // 后面的机会就会小.因为每个概率都会至少要算一次,所以先算大的 // 可以尽量减少后面再算大的. // 2

cf702C Cellular Network

C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line

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 input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line

Educational Codeforces Round 15_C. Cellular Network

C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line

UVa 457 - Linear Cellular Automata

题目:有40个培养皿,每个培养皿中有一个数字(0-9).最开始时20号中数字为1,其余为0. 每组输入有一个DNA programs(10个数字构成的序列),它决定每个培养皿下个时间的数字. 设培养皿i中的数字为F(i),则下次其中的数字为DNA(F(i-1)+F(i)+F(i+1)) {即,编号为F(i-1)+F(i)+F(i+1)的DNA programs中对应的数字}. 在给定DNA programs的情况下,输出所有培养皿中从第1-50天的数字. 分析:模拟,dp.读完题目,问题也基本解

UVa - 457 - Linear Cellular Automata 题解

本题大概题意: 给出一个数组DNA,包含10个数值,如:DNA[10] = {0,1,2,3,,1,2,3,0,1,2}所有数值应该不大于3. 给出一行40个字符的字符串: 空格代表0, '.'代表1,'x'代表2,'W'代表3. 相邻三个数值(或两个数值)相加得到的数作为DNA的下标,然后取DNA数组改下标的数值为新的值.产生新的字符串. 好难说清楚,看原文吧,的确是很难理解的题目: http://uva.onlinejudge.org/index.php?option=com_onlinej

codeforces 702C C. Cellular Network(水题)

题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same

CodeForce-702C Cellular Network(查找)

Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 r ,使得所有城市都能被照亮. Input 3 2-2 2 4-3 0 Output 4 Input 5 31 5 10 14 174 11 15 Output 3 题解: 首先对于每个城市 a[ i ],找到离它最近的左右两个灯塔  b [ x ] , b [ x-1 ](只有最左或最右灯塔时

CodeForces - 702C Cellular Network

You are given n points on the straight line - the positions (x-coordinates) of the cities and m points on the same line - the positions (x-coordinates) of the cellular towers. All towers work in the same way - they provide cellular network for all ci