Alx09

Ex3 Bun

May 8th, 2020
1,753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. unsigned ZigZag(unsigned n, unsigned i, unsigned j, unsigned pivot, unsigned lung) {
  5.     if (lung) {
  6.         n = n - ((2 * (i > lung) + (j > lung) ) * pivot);
  7.         if (i > lung ) i -= lung;
  8.         if (j > lung ) j -= lung;
  9.  
  10.         return ZigZag(n, i, j, pivot/ 4, lung /2);
  11.     }
  12.     return n;
  13. }
  14.  
  15. int main() {
  16.     unsigned n, i, j , q;
  17.     FILE *f, *g;
  18.     f = fopen("in.txt", "r");
  19.     g = fopen("out.txt", "w");
  20.     fscanf(f, "%u%u", &n, &q);
  21.  
  22.     while (q) {
  23.         fscanf(f, "%u%u", &i, &j);
  24.         fprintf(g, "%u\n", ZigZag(1 << 2 * n, i, j ,  1 << 2 *(n-1), 1 <<( n - 1)));
  25.         q--;
  26.     }
  27.     fclose(f);
  28.     fclose(g);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment