poj1018 Communication System

真是不知道为什么,枚举的时候明明没有枚举全啊!选定一个最小bandwidth之后,只枚举了一种情况,然后就进入下一个bandwidth的循环了。

比如最小带宽为80,后面有两个数据(85,100,2)和(86,50,2),这个时候循环就只会去枚举(85,100,2),不会去枚举(86,50,2),为啥这样也能通过呢。。。。。

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 using namespace std;
 5 struct Device
 6 {
 7     int band;
 8     int price;
 9     int id;
10 };
11 Device device[10000];
12 int pos;    //length
13 int MaxB[100];  //ith device maximum bandwidth;
14 bool visit[100];    //100 devices
15 int manu[100];
16 bool cmp(const Device& dev1,const Device& dev2)
17 {
18     if(dev1.band!=dev2.band)
19         return dev1.band<dev2.band;
20     return dev1.price<dev2.price;
21 }
22 int main()
23 {
24     int cases,n,m;
25     int bandwidth,price;
26     int maxB=0;
27     scanf("%d",&cases);
28     int i,j,k;
29     for(i=0;i<cases;i++)
30     {
31         scanf("%d",&n);     //n is the classes of device
32         pos=0;
33         for(j=0;j<n;j++)    //jth device
34         {
35             scanf("%d",&manu[j]);
36             maxB=0;
37             for(k=0;k<manu[j];k++)
38             {
39                 scanf("%d%d",&bandwidth,&price);
40                 device[pos].band=bandwidth;
41                 device[pos].price=price;
42                 device[pos].id=j;
43                 pos++;
44                 if(maxB<bandwidth)
45                     maxB=bandwidth;
46             }
47             MaxB[j]=maxB;
48         }
49         sort(device,device+pos,cmp);
50         float ans=0;
51         for(j=0;j<=(pos-n);j++)
52         {
53             bool flag=false;
54             int total=device[j].price,count=1;
55             memset(visit,false,sizeof(visit));
56             visit[device[j].id]=true;
57             for(k=j+1;k<pos;k++)
58             {
59                 if(visit[device[k].id])
60                     continue;
61                 if(device[j].band>MaxB[device[k].id])
62                 {
63                     flag=true;
64                     break;
65                 }
66                 total+=device[k].price;
67                 count++;
68                 visit[device[k].id]=true;
69             }
70             if(flag || count<n)
71                 continue;
72             float tmp=((float)device[j].band)/total;
73             if(ans<tmp)
74                 ans=tmp;
75         }
76         printf("%.3f\n",ans);
77     }
78     return 0;
79 }

 

posted @ 2012-10-13 15:34  sidereal  Views(167)  Comments(0)    收藏  举报