can any1 please post the solution to question number 670 in UVa Online
Judge http://uva.onlinejudge.org/external/6/670.html
I get "Wrong Answer" after the code runs for 2.8 sec properly..
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
//BEGIN_TEMPLATE_BY_PRATYUSH_VERMA
#define INF (1<<31)-1
#define REP(i,a) for((i)=0;(i)<(a);(i)++)
#define FOR(i,a,b) for((i)=(a);(i)<(b);(i)++)
#define FOREACH(i,c) for(__typeof((c).begin()) (i)=(c).begin();(i)!
=(c).end();(i)++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x.size()))
#define LENGTH(x) ((int)(x.length()))
#define SZ(x) sizeof(x)
#define MEM(m,i) memset((m),(i),SZ(m))
#define PB(x,y) (x).push_back(y)
#define MP(x,y) make_pair(x,y)
typedef long long ll;
//struct Point { ll x, y; Point() {} Point(ll a, ll b) {x=a;y=b;} ll
dist(Point a) { return (((a.x-x)*(a.x-x))+((a.y-y)*(a.y-y)));} bool
operator== (Point a, Point b) {if(a.x==b.x && a.y==b.y) return
true;return false;} bool operator<= (Point a, Point b)
{if(a.dist(Point(0,0))<=b.dist(Point(0,0))) return true;return
false;}};
//END_TEMPLATE_BY_PRATYUSH_VERMA
using namespace std;
int adj[205][205],M,N,from[205];
ll dist(int a, int b, int c, int d)
{
return (((a-c)*(a-c))+((b-d)*(b-d)));
}
int find_path()
{
int i,j;
bool v[205]={false};
queue<int> q;
q.push(0);
MEM(from,-1);
v[0]=true;
while(!q.empty())
{
int t=q.front();
q.pop();
FOR(i,1,M+N+2)
{
if(adj[t][i]==0 || v[i]) continue;
v[i]=true;
from[i]=t;
if(i==M+N+1) break;
q.push(i);
}
if(i!=M+N+2) break;
}
int where=M+N+1;
int path_cap=INF;
while(from[where]>-1)
{
int prev=from[where];
path_cap=min(path_cap,adj[prev][where]);
where=prev;
}
where=M+N+1;
int prev;
while(from[where]>-1)
{
prev=from[where];
adj[prev][where] -= path_cap;
adj[where][prev] += path_cap;
where = prev;
}
if(path_cap == INF)
return 0;
return path_cap;
}
int main()
{
ios_base::sync_with_stdio(0);
int test;
cin>>test;
while(test--)
{
ll p,q,i,j,k,x,y,z;
MEM(adj,0);
cin>>N>>M;
int nx[105],ny[105],mx[105],my[105];
int orig[205][205];
FOR(i,1,N+1)
adj[0][i]=INF;
FOR(i,N+1,N+M+1)
adj[i][N+M+1]=INF;
FOR(i,1,N+1)
{
cin>>nx[i]>>ny[i];
}
FOR(i,1,M+1)
{
cin>>mx[i]>>my[i];
}
FOR(i,1,N)
FOR(j,1,M+1)
{
if(sqrt(dist(nx[i],ny[i],mx[j],my[j]))+sqrt(dist(mx[j],my[j],nx[i
+1],ny[i+1]))<=2*(sqrt(dist(nx[i],ny[i],nx[i+1],ny[i+1]))))
adj[i][N+j]=1;
}
memcpy(orig,adj,SZ(adj));
int result=0;
while(1)
{
int path_cap=find_path();
if(path_cap==0) break;
result+=path_cap;
}
cout<<result<<endl;
FOR(i,1,N+1)
{
cout<<nx[i]<<" "<<ny[i]<<" ";
FOR(j,N+1,M+N+2)
{
if(orig[i][j]==1 && orig[i][j]!=adj[i][j])
{
if(i==N)
cout<<mx[j-N]<<" "<<my[j-N]<<endl;
else
cout<<mx[j-N]<<" "<<my[j-N]<<" ";
break;
}
}
// cout<<nx[i]<<" "<<ny[i];
}
if(test!=0)
cout<<endl;
}
return 0;
}
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.