Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- long int i, j, m, n, num_hs, num_reqs, min_dis, id_hs;
- long int k = 1;
- scanf("%ld %ld", &m, &n);
- while(m != 0 && n != 0){
- if(k > 1) printf("\n");
- scanf("%ld", &num_hs);
- long int hs_x[num_hs], hs_y[num_hs];
- for(i = 0; i < num_hs; i++){
- scanf("%ld %ld", &hs_x[i], &hs_y[i]);
- }
- scanf("%ld", &num_reqs);
- long int req_x[num_reqs], req_y[num_reqs];
- for(i = 0; i < num_reqs; i++){
- scanf("%ld %ld", &req_x[i], &req_y[i]);
- }
- printf("Instancia %ld\n", k);
- for(i = 0; i < num_reqs; i++){
- min_dis = abs(req_x[i] - hs_x[0]) + abs(req_y[i] - hs_y[0]);
- id_hs = 0;
- for(j = 1; j < num_hs; j++){
- if(abs(req_x[i] - hs_x[j]) + abs(req_y[i] - hs_y[j]) < min_dis){
- min_dis = abs(req_x[i] - hs_x[j]) + abs(req_y[i] - hs_y[j]);
- id_hs = j;
- }else if(abs(req_x[i] - hs_x[j]) + abs(req_y[i] - hs_y[j]) == min_dis){
- if(hs_x[j] < hs_x[id_hs]){
- id_hs = j;
- }else if(hs_x[j] == hs_x[id_hs]) {
- if(hs_y[j] < hs_y[id_hs]){
- id_hs = j;
- }
- }
- }
- }
- printf("%ld %ld\n", hs_x[id_hs], hs_y[id_hs]);
- }
- scanf("%ld %ld", &m, &n);
- k++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment