Skip to content

Instantly share code, notes, and snippets.

@Abreto
Created May 29, 2012 15:08
Show Gist options
  • Save Abreto/2828953 to your computer and use it in GitHub Desktop.
Save Abreto/2828953 to your computer and use it in GitHub Desktop.
AStar2012-J
#include <stdio.h>
int main(void)
{
int n = 0, m = 0;
int u = 0, d = 0, t = 0;
int l = 0, low = -1;
scanf("%d %d", &n, &m);
while(m--)
{
scanf("%d %d", &u, &d);
t = (int)(( (n*d) / (u+d) ) + 1);
l = (u+d)*t-n*d;
if( ((l < low) && low >= 0) || (low < 0) )
low = l;
}
printf("%d\n", low);
}
@luztak
Copy link

luztak commented May 29, 2012

t=((n_d)/(u+d))+1
->t=(n_d+u+d)/(u+d)
l=(u+d)t-n_d=n_d+u+d-n*d=u+d.

当然,没考虑分数.

@luztak
Copy link

luztak commented May 29, 2012

t=((n_d)/(u d)) 1
->t=(n_d u d)/(u d)
l=(u d)t-n_d=n_d u d-n*d=u d.

当然,没考虑分数.

@luztak
Copy link

luztak commented May 29, 2012

t=((n_d)/(u d)) 1
->t=(n_d u d)/(u d)
l=(u d)t-n_d=n_d u d-n*d=u d.

当然,没考虑分数.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment