QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#115171 | #5811. Wi-fi Towers | zhouhuanyi | 28 ✓ | 10ms | 3680kb | C++11 | 2.0kb | 2023-06-24 19:42:03 | 2023-06-24 19:42:03 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<queue>
#define N 2000
#define M 2500000
#define inf 1e9
using namespace std;
int read()
{
char c=0;
int sum=0,f=1;
while (c!='-'&&(c<'0'||c>'9')) c=getchar();
if (c=='-') c=getchar(),f=-1;
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum*f;
}
struct node
{
int v,data,nxt;
};
node edge[M+1];
struct reads
{
int x,y,r,s;
};
reads st[N+1];
int T,n,len,s,t,ans,head[N+1],cur[N+1],depth[N+1];
void add(int x,int y,int z)
{
edge[++len]=(node){y,z,head[x]},head[x]=len;
edge[++len]=(node){x,0,head[y]},head[y]=len;
return;
}
bool bfs()
{
int top;
queue<int>q;
for (int i=s;i<=t;++i) depth[i]=0;
q.push(s),depth[s]=1;
while (!q.empty())
{
top=q.front(),q.pop();
for (int i=head[top];i>0;i=edge[i].nxt)
if (edge[i].data&&!depth[edge[i].v])
depth[edge[i].v]=depth[top]+1,q.push(edge[i].v);
}
return depth[t]>0;
}
int dinic(int x,int flow)
{
if (x==t) return flow;
int k;
for (int &i=cur[x];i>0;i=edge[i].nxt)
if (edge[i].data&&depth[edge[i].v]==depth[x]+1)
{
k=dinic(edge[i].v,min(flow,edge[i].data));
if (k)
{
edge[i].data-=k,edge[i^1].data+=k;
return k;
}
}
return 0;
}
int main()
{
int flow;
T=read();
for (int qt=1;qt<=T;++qt)
{
n=read(),s=0,t=n+1,len=1,ans=0;
for (int i=s;i<=t;++i) head[i]=0;
for (int i=1;i<=n;++i) st[i].x=read(),st[i].y=read(),st[i].r=read(),st[i].s=read();
for (int i=1;i<=n;++i)
{
if (st[i].s>0) add(s,i,st[i].s),ans+=st[i].s;
if (st[i].s<0) add(i,t,-st[i].s);
}
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
if (i!=j)
if ((st[i].x-st[j].x)*(st[i].x-st[j].x)+(st[i].y-st[j].y)*(st[i].y-st[j].y)<=st[i].r*st[i].r)
add(i,j,inf);
while (bfs())
{
for (int i=s;i<=t;++i) cur[i]=head[i];
while (flow=dinic(s,inf)) ans-=flow;
}
printf("Case #%d: %d\n",qt,ans);
}
return 0;
}
详细
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 0ms
memory: 3680kb
input:
55 15 10 12 45 -1 9 5 50 1 5 20 41 1 11 8 50 1 20 13 44 1 2 0 45 -1 5 4 47 -1 14 13 42 -1 19 1 47 -1 8 0 41 -1 8 16 40 -1 15 11 42 1 8 8 42 1 2 9 50 1 0 10 44 1 15 872 2191 2 -386 -2071 -3796 1 -568 4237 -5305 6742 275 -2307 -6269 1 -148 6875 -19 461 -519 -9871 -3500 64 -306 -2576 -5709 25 686 431 8...
output:
Case #1: 1 Case #2: 3091 Case #3: 923 Case #4: 651 Case #5: 1387 Case #6: 1319 Case #7: 1 Case #8: 747 Case #9: 0 Case #10: 1443 Case #11: 2 Case #12: 0 Case #13: 1746 Case #14: 1533 Case #15: 687 Case #16: 1851 Case #17: 2140 Case #18: 886 Case #19: 673 Case #20: 0 Case #21: 1772 Case #22: 0 Case #...
result:
ok 55 lines
Subtask #2:
score: 25
Accepted
Test #2:
score: 25
Accepted
time: 10ms
memory: 3676kb
input:
55 5 0 -1 7 10 0 1 7 10 5 0 1 -15 10 0 6 10 15 1 2 -20 171 46 50 3 3 30 6 8 2 14 30 8 2 10 10 8 4 48 28 1 -2 18 18 9 3 52 12 1 -2 54 6 10 4 26 54 10 4 24 36 1 -1 30 14 3 1 4 36 1 -1 40 4 1 -2 14 14 9 4 52 40 1 -3 20 48 1 -2 50 6 8 3 16 16 1 -3 10 42 3 2 50 38 7 3 44 52 1 -2 4 48 1 -2 16 52 1 -1 32 5...
output:
Case #1: 5 Case #2: 24 Case #3: 18455 Case #4: 46 Case #5: 34885 Case #6: 12211 Case #7: 4653 Case #8: 3560 Case #9: 16236 Case #10: 64 Case #11: 12885 Case #12: 18102 Case #13: 17 Case #14: 10 Case #15: 3824 Case #16: 2589 Case #17: 3949 Case #18: 1 Case #19: 0 Case #20: 28 Case #21: 40141 Case #22...
result:
ok 55 lines
Extra Test:
score: 0
Extra Test Passed