bzoj1565

很明显是最大权闭合子图,但要注意
互相保护的植物打不掉,被互相保护的植物所直接或间接保护的植物也打不掉
我们先拓扑排序然后dfs出能打掉的点,然后做最大权闭合子图

  1 const inf=1000000007;
  2 type node=record
  3        po,flow,next:longint;
  4      end;
  5 
  6 var e,w:array[0..800010] of node;
  7     num:array[0..21,0..32] of longint;
  8     cur,pre,p,st,q,numh,s,h,d:array[0..700] of longint;
  9     can,v:array[0..700] of boolean;
 10     n,m,i,j,x,y,len,k,t,f:longint;
 11 
 12 function min(a,b:longint):longint;
 13   begin
 14     if a>b then exit(b) else exit(a);
 15   end;
 16 
 17 procedure add(x,y:longint);
 18   begin
 19     inc(len);
 20     w[len].po:=y;
 21     inc(d[y]);
 22     w[len].next:=q[x];
 23     q[x]:=len;
 24   end;
 25 
 26 procedure ins(x,y,f:longint);
 27   begin
 28     inc(len);
 29     e[len].po:=y;
 30     e[len].flow:=f;
 31     e[len].next:=p[x];
 32     p[x]:=len;
 33   end;
 34 
 35 procedure build(x,y,f:longint);
 36   begin
 37     ins(x,y,f);
 38     ins(y,x,0);
 39   end;
 40 
 41 procedure dfs(x:longint);
 42   var i,y:longint;
 43   begin
 44     v[x]:=true;
 45     can[x]:=false;
 46     i:=q[x];
 47     while i<>0 do
 48     begin
 49       y:=w[i].po;
 50       if not v[y] then dfs(y);
 51       i:=w[i].next;
 52     end;
 53   end;
 54 
 55 function sap:longint;
 56   var i,j,u,tmp,neck,q:longint;
 57   begin
 58     u:=0;
 59     sap:=0;
 60     for i:=0 to t do
 61       cur[i]:=p[i];
 62     numh[0]:=t+1;
 63     neck:=inf;
 64     while h[0]<t+1 do
 65     begin
 66       i:=cur[u];
 67       d[u]:=neck;
 68       while i<>-1 do
 69       begin
 70         j:=e[i].po;
 71         if (e[i].flow>0) and (h[u]=h[j]+1) then
 72         begin
 73           neck:=min(neck,e[i].flow);
 74           cur[u]:=i;
 75           pre[j]:=u;
 76           u:=j;
 77           if u=t then
 78           begin
 79             sap:=sap+neck;
 80             while u<>0 do
 81             begin
 82               u:=pre[u];
 83               j:=cur[u];
 84               dec(e[j].flow,neck);
 85               inc(e[j xor 1].flow,neck);
 86             end;
 87             neck:=inf;
 88           end;
 89           break;
 90         end;
 91         i:=e[i].next;
 92       end;
 93       if i=-1 then
 94       begin
 95         dec(numh[h[u]]);
 96         if numh[h[u]]=0 then exit;
 97         q:=-1;
 98         tmp:=t;
 99         i:=p[u];
100         while i<>-1 do
101         begin
102           j:=e[i].po;
103           if e[i].flow>0 then
104             if h[j]<tmp then
105             begin
106               q:=i;
107               tmp:=h[j];
108             end;
109           i:=e[i].next;
110         end;
111         h[u]:=tmp+1;
112         inc(numh[h[u]]);
113         cur[u]:=q;
114         if u<>0 then
115         begin
116           u:=pre[u];
117           neck:=d[u];
118         end;
119       end;
120     end;
121   end;
122 
123 begin
124   readln(n,m);
125   for i:=0 to n-1 do
126     for j:=0 to m-1 do
127     begin
128       inc(k);
129       num[i,j]:=k;
130     end;
131 
132   for i:=1 to n*m do
133   begin
134     read(s[i],k);
135     for j:=1 to k do
136     begin
137       read(x,y);
138       add(i,num[x,y]);
139     end;
140   end;
141   for i:=0 to n do
142     for j:=m-1 downto 1 do
143       add(num[i,j],num[i,j-1]);
144 
145   f:=1; t:=0;
146   for i:=1 to n*m do
147     if d[i]=0 then
148     begin
149       inc(t);
150       st[t]:=i;
151     end;
152 
153   while f<=t do
154   begin
155     x:=st[f];
156     can[x]:=true;
157     i:=q[x];
158     while i<>0 do
159     begin
160       y:=w[i].po;
161       dec(d[y]);
162       if d[y]=0 then
163       begin
164         inc(t);
165         st[t]:=y;
166       end;
167       i:=w[i].next;
168     end;
169     inc(f);
170   end;
171   for i:=1 to n*m do
172     if not can[i] then
173     begin
174       fillchar(v,sizeof(v),false);
175       dfs(i);
176     end;
177   t:=n*m+1; k:=0; len:=-1;
178   fillchar(p,sizeof(p),255);
179   for i:=1 to n*m do
180     if can[i] then
181     begin
182       if s[i]>0 then
183       begin
184         build(0,i,s[i]);
185         k:=k+s[i];
186       end
187       else build(i,t,-s[i]);
188       j:=q[i];
189       while j<>0 do
190       begin
191         y:=w[j].po;
192         if can[y] then build(y,i,inf);
193         j:=w[j].next;
194       end;
195     end;
196   writeln(k-sap);
197 end.
View Code

 

转载于:https://www.cnblogs.com/phile/p/4472939.html

BZOJ 2908 题目是一个数据下载任务。这个任务要求下载指定的数据文件,并统计文件中小于等于给定整数的数字个数。 为了完成这个任务,首先需要选择一个合适的网址来下载文件。我们可以使用一个网络爬虫库,如Python中的Requests库,来帮助我们完成文件下载的操作。 首先,我们需要使用Requests库中的get()方法来访问目标网址,并将目标文件下载到我们的本地计算机中。可以使用以下代码实现文件下载: ```python import requests url = '目标文件的网址' response = requests.get(url) with open('本地保存文件的路径', 'wb') as file: file.write(response.content) ``` 下载完成后,我们可以使用Python内置的open()函数打开已下载的文件,并按行读取文件内容。可以使用以下代码实现文件内容读取: ```python count = 0 with open('本地保存文件的路径', 'r') as file: for line in file: # 在这里实现对每一行数据的判断 # 如果小于等于给定整数,count 加 1 # 否则,不进行任何操作 ``` 在每一行的处理过程中,我们可以使用split()方法将一行数据分割成多个字符串,并使用int()函数将其转换为整数。然后,我们可以将该整数与给定整数进行比较,以判断是否小于等于给定整数。 最后,我们可以将统计结果打印出来,以满足题目的要求。 综上所述,以上是关于解决 BZOJ 2908 数据下载任务的简要步骤和代码实现。 希望对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值