[UVA] 1047 - Zones@Morris' Blog|PChome Online 人新台
2013-07-18 13:40:19| 人1,066| 回0 | 上一篇 | 下一篇

[UVA] 1047 - Zones

0 收藏 0 0 站台

Telephone poles are part of an outdated technology. Cell phones nowadays allow us to call whoever we want, wherever we want, independent of any wire. There is one problem - without a service tower nearby a cell phone is useless.


In the absence of hills and mountains, a service tower will provide coverage for a circular area. Instead of planning where to place the wires, a wireless telephone company has to plan where to build its service towers. Building the towers too far apart causes holes in the coverage and increases complaints. Building the towers too close to each other results in large areas covered by more than one service tower, which is redundant and inefficient.


International Cell Phone Company is developing a network strategy to determine the optimal placement of service towers. Since most customers have replaced their old wired home phones by cell phones, the strategy for planning service towers is therefore to cover as many homes of customers as possible.


The figure below shows the service areas for the five towers ICPC's strategic department planned to build this year. Tower 5 will serve 24 customers, 6 of which are also served by tower 4. Towers 1, 2 and 3 have a common service area containing 3 customers.

epsfbox{p3278.eps}

Shortly after the plans for these five towers had been published, higher management issued a stop on all tower building. Protesting customers forced them to weaken this decree, and allow the building of three towers out of the five planned. These three towers should serve as many customers as possible, of course. Finding the best possible choice for the towers to build is not trivial (the best choice in this case is towers 2, 4 and 5, serving 68 customers).


You must write a program to help ICPC choose which towers to build in cases like these. If several choices of towers serve the same number of customers, choices including tower 1 are preferable. If this rule still leaves room for more than one solution, solutions including tower 2 are preferable, and so on.

Input 

The input file contains several test cases. The first line of each test case contains two positive integers: the number n (n$ le$20) of towers planned, and the number of towers to be actually built. The next line contains n numbers, each giving the number of customers served by a planned tower. (The first number refers to the first tower, and so on.) No tower serves more than a million people. The next line contains the number m (m$ le$10) of common service areas. Each of the next m lines contains the description of a common service area. Such a line starts with the number t (t > 1) of towers for which this is a common service area, followed by the t numbers of the towers. The last number on the line is the number of customers in the common service area. The last line of the input file consists of the two integers `0 0'.

Output 

For each test case, display the number of customers served and the best choice for the location of the towers. Follow the format of the sample output. All numbers are left-justified nd there are no blank spaces at the end of any line. Print a blank line after each test case.

Sample Input 

5 3 15 20 25 30 24 5 2 1 2 7 3 1 2 3 3 2 2 3 2 2 3 4 5 2 4 5 6 5 3 25 25 25 25 25 4 2 1 2 5 2 2 3 5 2 3 4 5 2 4 5 5 5 3 25 25 25 25 25 0 0 0 

Sample Output 

Case Number 1 Number of Customers: 68 Locations recommended: 2 4 5 Case Number 2 Number of Customers: 75 Locations recommended: 1 3 5 Case Number 3 Number of Customers: 75 Locations recommended: 1 2 3 

目描述:

定一些基地台的置,以及交集的服人,然而只能建造特定的塔,
一能服最多的置方法,相同取字典序最小的取法。

目解法:


模。


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int rmask[20] = {}, mw[20], c[20];
int mx, ret;
int n, m, r;
int i;
void dfs(int idx, int n, int m, int mask, int i) {
if(idx == m) {
int sum = 0;
for(i = 0; i < n; i++)
if((mask>>i)&1)
sum += c[i];
for(i = 0; i < r; i++) {
int val = __builtin_popcount(mask&rmask[i]);
if(val >= 2)
sum -= mw[i]*(val-1);
}
if(sum > mx) {
mx = sum;
ret = mask;
}
return;
}
for(; i < n; i++)
dfs(idx+1, n, m, mask|(1<<i), i+1);
}
int main() {
int cases = 0;
while(scanf("%d %d", &n, &m) == 2 && n) {
for(i = 0; i < n; i++)
scanf("%d", &c[i]);
scanf("%d", &r);
for(i = 0; i < r; i++) {
rmask[i] = 0;
int x, y;
scanf("%d", &x);
while(x--) {
scanf("%d", &y);
y--;
rmask[i] |= 1<<y;
}
scanf("%d", &mw[i]);
}
mx = 0, ret = 0;
dfs(0, n, m, 0, 0);
printf("Case Number %d\n", ++cases);
printf("Number of Customers: %d\n", mx);
printf("Locations recommended:");
for(i = 0; i < n; i++)
if((ret>>i)&1)
printf(" %d", i+1);
puts("\n");
}
return 0;
}

台: Morris
人(1,066) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA][模] 1064 - Network
此分上一篇:[UVA] 234 - Switching Channels

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86