Guest User

Untitled

a guest
Sep 16th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef enum {
  4.     OK,
  5.     RISOLTO,
  6.     IMPOSSIBILE
  7. } stato_t;
  8.  
  9. typedef struct {
  10.     int domino1;
  11.     int domino2;
  12. } coppia_t;
  13.  
  14. stato_t correggi(int N, int altezze[], coppia_t* scambio) {
  15.     int okTo = 0;
  16.     bool ok = 1;
  17.     vector<int> notKnocked;
  18.     for(int i = 0; i < N; i++) {
  19.         if(okTo<i) {
  20.             ok = 0;
  21.             notKnocked.push_back(i);
  22.         }
  23.         okTo = max(okTo, i+altezze[i]-1);
  24.     }
  25.     if(ok)
  26.         return OK;
  27.  
  28.     int l = notKnocked[0];
  29.     int r = notKnocked.back();
  30.     if(N>100000) {
  31.         return IMPOSSIBILE;
  32.     }
  33.  
  34.     for(int x = 0; x < N; x++) {
  35.         for(int y = max(0,r-altezze[x]+1); y < l; y++) {
  36.             swap(altezze[x], altezze[y]);
  37.             int okTo = 0;
  38.             bool ok = 1;
  39.             for(int i = 0; i < N; i++) {
  40.                 if(okTo<i)
  41.                     ok = 0;
  42.                 okTo = max(okTo, i+altezze[i]-1);
  43.             }
  44.             if(ok) {
  45.                 scambio->domino1 = x;
  46.                 scambio->domino2 = y;
  47.                 return RISOLTO;
  48.             }
  49.             swap(altezze[x], altezze[y]);
  50.         }
  51.     }
  52.  
  53.     return IMPOSSIBILE;
  54. }
Add Comment
Please, Sign In to add comment