Bzoj 1822: [Jsoi2010]frozen Nova frozen Wave

Source: Internet
Author: User

"Original question"

1822: [Jsoi2010]frozen Nova Freeze Wave time limit: ten Sec Memory Limit: MB
Submit: 796 Solved: 218
[Submit] [Status] DESCRIPTIONWJJ Likes "Warcraft" this game. In the game, the Lich is a powerful hero, and its skill frozen Nova can kill one elf at a time. We believe that both the Lich and the elf can be seen as a point on the plane. When a straight line between the Lich and the elf does not exceed R, and the Lich sees the elf's sight without being blocked by the trees (that is, the Lich and the elf are not connected to any of the trees), the lich can kill a little elf in a jiffy. There are n witches in the forest, and after each Lich releases frozen Nova, it will take some time before it can be cast again. Different lich have different wait time and cast range, but the same is, each cast can kill a elf. Now the Lich's leader wants to know how long it will take at least to kill all the elves if it starts counting from 0 hours? The first line of the input file contains three integers N, M, K (n,m,k<=200), each representing the number of lich, the number of elves, and the number of trees. Next n rows, each line contains four integers x, y, R, T, each representing the coordinates of each lich, the range of attack, and the cast interval (in seconds). The next M-line, two integers x, y, each represents the coordinates of each elf. The next k lines, three integers x, y, R for each row, represent the coordinates of each tree, respectively. The absolute value of all coordinate ranges in the input data does not exceed 10000, and the radius and cast interval does not exceed 20000. Output outputs a line that is the shortest time (in seconds) to eliminate all sprites. If you can never destroy all the elves, then output-1. Sample Input2 3 1
-100 0 100 3
100 0 100 5
-100-10
100 10
110 11
5 5 10
Sample Output5HINT

Source

JSOI2010 Second round Contest1


"Analysis" The recent brush problem is a bit smooth (basically do not see the key). Like this problem, just two minutes to enumerate the answers and then the network flow verification. However, the difficulty of this problem is how to determine whether a "Lich" to "Elf" can be hit. is actually to determine whether a straight line can drink a circle to produce intersections.

Because not the operation of the vector, I also foolishly use the analytic formula of kx+b to calculate. Then it is formed into one-yuan two-time equation to find discriminant. Then WA was unusually long, and later found to have been precision stuck. such as circle and line tangent is feasible, and then I will be sentenced to have an intersection, the default is not OK = =.

PS: In addition to vectors, there is also a calculation method, that is, the distance between the center of the line and the relationship between R.

Code

#include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #define INF 2139062143#define N 405using namespace std;struct arr{int x,y,r,t;} Kill[n],p[n],tree[n];struct arr{int Go,s,next;} A[n*n];int end[n],f[n],f[n][n],q[n*100];const long double eps=1e-6;int N,m,k,i,j,flag,w,error,ans,s,t,cnt;bool get_  Root () {int x1=kill[i].x,y1=kill[i].y,x2=p[j].x,y2=p[j].y,a=tree[w].x,b=tree[w].y,r=tree[w].r;  Long double k= (x1==x2) 1e30+0.0: ((y1-y2) *1.0/(x1-x2)), b=y1-k*1.0*x1+0.0;  Long double aa=1.0+1.0*k*k,bb=-2.0*a+2.0*k* (b-b), cc=1.0*a*a+1.0* (b-b) * (b-b) -1.0*r*r;  a long double temp=bb*bb-4*aa*cc;  return (temp>0);  a long double aa=k,bb=-1.0,cc=b;  Long double dis= (AA*A+BB*B+CC)/sqrt (AA*AA+BB*BB); return (DIS+EPS&LT;=R);}  inline bool BFs () {memset (f,-1,sizeof (f));  int h=0,t=1;q[1]=s;f[s]=1;    while (h<t) {int now=q[++h];if (now==t) return 1;      for (int i=end[now];i;i=a[i].next) {int go=a[i].go; if (F[GO]==-1&AMP;&AMP;A[I].S) f[go]=F[now]+1,q[++t]=go; }} return 0;}  int dinic (int sta,int sum) {if (sta==t) return sum;  int os=sum;    for (int i=end[sta];i&&os;i=a[i].next) {int go=a[i].go;      if (F[GO]==F[STA]+1&AMP;&AMP;A[I].S) {int min=dinic (go,min (OS,A[I].S));    A[i].s-=min;a[i^1].s+=min;os-=min; }} if (os==sum) F[sta]=-1;return Sum-os;}  inline void Add (int u,int v,int W) {a[++cnt].go=v;a[cnt].s=w;a[cnt].next=end[u];end[u]=cnt; a[++cnt].go=u;a[cnt].s=0;a[cnt].next=end[v];end[v]=cnt;}  inline bool Check (int time) {memset (end,0,sizeof (end)); s=0; T=n+m+1;cnt=1;  time++;  for (int i=1;i<=n;i++) Add (S,i, (time+kill[i].t-1)/(kill[i].t));  for (int i=1;i<=m;i++) Add (n+i,t,1);  for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (F[i][j]) Add (i,n+j,1);  int flow=0;  while (BFS ())) flow+=dinic (S,inf); if (flow<m) return 0;error=0;return 1;}  int erfen (int l,int r) {if (l==r) return l;  int mid= (L+R) >>1;  if (check (mid)) return Erfen (L,mid); Return Erfen (MID+1,R);}inline int dis (arr A,arr b) {return (a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y);}  int main () {scanf ("%d%d%d", &n,&m,&k);  for (i=1;i<=n;i++) scanf ("%d%d%d%d", &kill[i].x,&kill[i].y,&kill[i].r,&kill[i].t);  for (i=1;i<=m;i++) scanf ("%d%d", &p[i].x,&p[i].y);  for (i=1;i<=k;i++) scanf ("%d%d%d", &AMP;TREE[I].X,&AMP;TREE[I].Y,&AMP;TREE[I].R);      for (i=1;i<=n;i++) for (j=1;j<=m;j++) {flag=1;      if (DIS (kill[i],p[j]) &GT;KILL[I].R*KILL[I].R) continue;      for (w=1;w<=k&&flag;w++) if (Get_root ()) flag=0;    F[i][j]=flag;  } error=1;ans=erfen ( -1,4000000);  if (error) ans=-1;printf ("%d", ans); return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.