Pagini recente » Cod sursa (job #692128) | Cod sursa (job #266263) | Cod sursa (job #1737860) | Cod sursa (job #578629) | Cod sursa (job #636953)
Cod sursa(job #636953)
#include <fstream>
using namespace std;
typedef struct portal
{
int x1,y1,x2,y2;
int c;
int m;
int r;
int f;
}
portal;
int main()
{
ifstream f ("portal3.in");
ofstream g ("portal3.out");
int i,j,k,t,temp;
int n,m,min;
portal p[3];
f>>t;
for (i=0;i<t;i++)
{
f>>n>>m;
for (j=0;j<3;j++)
{
f>>p[j].x1>>p[j].y1>>p[j].x2>>p[j].y2>>p[j].c;
p[j].m = p[j].x1+p[j].y1;
p[j].r = n-p[j].x2 + m-p[j].y2 + p[j].c;
p[j].f = 0;
}
for (j=0;j<3;j++)
{
for (k=0;k<3;k++)
{
if (k!=j)
{
if (p[j].x1 > p[k].x2)
temp = p[j].x1 - p[k].x2;
else
temp = p[k].x2 - p[j].x1;
if (p[j].y1 > p[k].y2)
temp+= p[j].y1 - p[k].y2;
else
temp+= p[k].y2 - p[j].y1;
//temp e distanta de la portalul k la portalul i;
if ((temp + p[k].m + p[k].c)<p[j].m) //daca drumu prin portalul k e mai mic decat drum drept
p[j].f=temp+p[k].m+p[k].c;
}
}
}
min=n+m;
for (j=0;j<3;j++)
{
if (p[j].f)
temp = p[j].f + p[j].r;
else
temp = p[j].m + p[j].r;
if (temp<min)
min = temp;
}
g<<min<<"\n";
}
f.close();
g.close();
return 0;
}