YEZAELP

o59_oct_c2_pointsoncircle

Jun 24th, 2021
701
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int N = 1e9 + 10;
  5. const int K = 1e3 + 10;
  6. int ar[K][K];
  7. int point1[K], point2[K], ans[K];
  8. int n, k;
  9.  
  10. bool dist(int a, int b, int d){
  11.     if(a > b) swap(a, b);
  12.     return (b-a == d) or (n-b+a == d);
  13. }
  14.  
  15. bool check(int a, int i){
  16.     for(int j=1;j<i;j++)
  17.         if(!dist(a, ans[j], ar[i][j])) return false;
  18.     for(int j=i+1;j<=k;j++)
  19.         if(!dist(a, point1[j], ar[i][j]) and !dist(a, point2[j], ar[i][j])) return false;
  20.     return true;
  21. }
  22.  
  23. int main(){
  24.  
  25.     scanf("%d%d", &n, &k);
  26.  
  27.     for(int i=1;i<=k;i++){
  28.         for(int j=1;j<=k;j++){
  29.             scanf("%d", &ar[i][j]);
  30.         }
  31.     }
  32.  
  33.     for(int j=2;j<=k;j++){
  34.         point1[j] = ar[1][j];
  35.         point2[j] = n - ar[1][j];
  36.     }
  37.  
  38.     ans[0] = 0;
  39.     for(int i=2;i<=k;i++){
  40.         if(check(point1[i], i)) ans[i] = point1[i];
  41.         else ans[i] = point2[i];
  42.     }
  43.  
  44.     for(int i=1;i<=k;i++) printf("%d\n", ans[i]);
  45.  
  46.     return 0;
  47. }
  48.  
RAW Paste Data