Codeforces Ronda # 628 (Div. 2) solución a un problema

Hierba, y casi perdido puntos

A: un método de combinación de buscar \ (A, B \) , por lo que \ (\ gcd (a, b ) + lcm (a, b) = n \)

Inicialmente pregunta equivocada sorprendió a 1min, hierba grande

a = 1, b = n-1 lata

B: usted \ (n- \) elementos, la replicación \ (\ n-) veces, la salida se eleva hasta la longitud estricto de la sub-secuencia.

Deduplicación puede, sólo puede tomar una copia de cada paso en el tiempo, pero exigente subida que van más pesado.

C: El \ (máx \ {Mex (u , v) \} \) es el valor mínimo.

Mispronounce wa fuera de la cuestión de nuevo

Consideramos, que es la misma cadena.

Entonces la cadena de grado 2 y, a continuación, se encontró que si el grado es 3, abrimos a la expansión en este punto, 0 y 1 en ambos lados de poner en él.

D: una secuencia más corta de configuración, y tal como \ (U \) , y a la exclusiva OR \ (V \)

sentencia especial de un montón me gusta / dk

signed main() {
  // code begin.
    int u , v;
    in >> u >> v;
    if(u > v) {
        out << -1 << '\n' ;
        return 0 ;
    }
    else {
        if(u == v && ! u && ! v) {
            out << 0 << '\n' ;
            return 0 ;
        }
        else {
            if(u == v) {
                out << 1 << '\n' ;
                out << u << '\n' ;
                return 0 ;
            }
            else {
                int left = v - u ;
                if(left & 1) {
                    out << -1 << '\n' ;
                    return 0 ;
                }
                else {
                    left >>= 1;
                    if(u & left) {
                        out << 3 << '\n' ;
                        out << u << ' ' << left << ' ' << left << '\n' ;
                        return 0 ;
                    }
                    else {
                        out << 2 << '\n' ;
                        out << (u | left) << ' ' << left << '\n';
                        return 0 ;
                    }
                }
            }
        }
    }
    return 0;
  // code end.
}

E: una serie para ti, es necesario seleccionar una subsecuencia, el título para asegurarse de que cada elemento hasta dos factores primos, por lo que el producto de esta secuencia es un cuadrado perfecto, y el más corto tal longitud.
Conectado entre el borde factores primos, si sólo hay un factor de calidad, e incluso a cero.
Entonces nos preguntamos por el anillo más pequeño, que es el registro ha llegado dos i punto, entonces en él.

// powered by c++11
// by Isaunoya
#include <bits/stdc++.h>
#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
#define Tp template
using pii = pair<int, int>;
#define fir first
#define sec second
Tp<class T> void cmax(T& x, const T& y) {
  if (x < y) x = y;
}
Tp<class T> void cmin(T& x, const T& y) {
  if (x > y) x = y;
}
#define all(v) v.begin(), v.end()
#define sz(v) ((int)v.size())
#define pb emplace_back
Tp<class T> void sort(vector<T>& v) { sort(all(v)); }
Tp<class T> void reverse(vector<T>& v) { reverse(all(v)); }
Tp<class T> void unique(vector<T>& v) { sort(all(v)), v.erase(unique(all(v)), v.end()); }
const int SZ = 1 << 23 | 233;
struct FILEIN {
  char qwq[SZ], *S = qwq, *T = qwq, ch;
#ifdef __WIN64
#define GETC getchar
#else
  char GETC() { return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T) ? EOF : *S++; }
#endif
  FILEIN& operator>>(char& c) {
    while (isspace(c = GETC()))
      ;
    return *this;
  }
  FILEIN& operator>>(string& s) {
    while (isspace(ch = GETC()))
      ;
    s = ch;
    while (!isspace(ch = GETC())) s += ch;
    return *this;
  }
  Tp<class T> void read(T& x) {
    bool sign = 0;
    while ((ch = GETC()) < 48) sign ^= (ch == 45);
    x = (ch ^ 48);
    while ((ch = GETC()) > 47) x = (x << 1) + (x << 3) + (ch ^ 48);
    x = sign ? -x : x;
  }
  FILEIN& operator>>(int& x) { return read(x), *this; }
  FILEIN& operator>>(ll& x) { return read(x), *this; }
} in;
struct FILEOUT {
  const static int LIMIT = 1 << 22;
  char quq[SZ], ST[233];
  int sz, O;
  ~FILEOUT() { flush(); }
  void flush() {
    fwrite(quq, 1, O, stdout);
    fflush(stdout);
    O = 0;
  }
  FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
  FILEOUT& operator<<(string str) {
    if (O > LIMIT) flush();
    for (char c : str) quq[O++] = c;
    return *this;
  }
  Tp<class T> void write(T x) {
    if (O > LIMIT) flush();
    if (x < 0) {
      quq[O++] = 45;
      x = -x;
    }
    do {
      ST[++sz] = x % 10 ^ 48;
      x /= 10;
    } while (x);
    while (sz) quq[O++] = ST[sz--];
  }
  FILEOUT& operator<<(int x) { return write(x), *this; }
  FILEOUT& operator<<(ll x) { return write(x), *this; }
} out;
//#define int long long

const int maxv = 1e3 ;
const int maxn = 1e6 ;
int isprime[maxv + 1];
vector<int> prime;
vector<int> g[maxn];
int d1[maxn], d2[maxn];
int f1[maxn], f2[maxn];

signed main() {
  // code begin.
  for (int i = 2; i <= maxv; i++) {
    if (!isprime[i]) {
      prime.pb(i);
      isprime[i] = sz(prime);
      for (int j = 2 * i; j <= maxv; j += i) isprime[j] = -1;
    }
  }
  int n;
  in >> n;
  int ans = n + 1;
  for (int i = 0; i < n; i++) {
    int x;
    in >> x;
    vector<int> d;
    for (int p : prime) {
      int cnt = 0;
      while (!(x % p)) x /= p, ++cnt;
      if (cnt & 1) d.pb(isprime[p]);
    }
    if (x == 1) {
      if (d.empty()) {
        out << 1 << '\n';
        return 0;
      } else if (sz(d) == 1) {
        g[d[0]].pb(0), g[0].pb(d[0]);
            }
      else {
        g[d[0]].pb(d[1]), g[d[1]].pb(d[0]);
            }
    } else if (d.empty()) {
      g[0].pb(x), g[x].pb(0);
        }
    else {
      g[d[0]].pb(x), g[x].pb(d[0]);
        }
  }
  for (int i = 0; i < 169; i++) {
    fill(d1, d1 + maxn, -1);
    fill(d2, d2 + maxn, -1);
    sort(g[i].begin() , g[i].end()) ;
    if (unique(g[i].begin() , g[i].end()) != g[i].end()) {
      out << 2 << '\n';
      return 0;
    }
    queue<int> q1, q2, q3;
    for (int v : g[i]) q1.push(v), q2.push(1), q3.push(v);
    while (!q1.empty()) {
      int u = q1.front(), d = q2.front(), f = q3.front();
      q1.pop(), q2.pop(), q3.pop();
      if (d1[u] == -1) {
        d1[u] = d, f1[u] = f;
      } else if (d2[u] == -1 && f1[u] ^ f) {
        d2[u] = d, f2[u] = f;
      } else {
        continue;
            }
      for (int v : g[u])
        if (v ^ i)
          q1.push(v), q2.push(d + 1), q3.push(f);
    }
    for (int v : g[i])
      if (~d2[v]) cmin(ans, d2[v] + 1);
  }
  if (ans > n) out << -1 << '\n';
  else out << ans << '\n';
  return 0;
  // code end.
}

F:

Fácilmente encontrar un árbol de expansión, y luego transversal en lo anterior, si hay un borde adyacente a los dos puntos están espaciados sqrt 2 puede ser una salida directa.
De lo contrario, teñidas 01, el resultado final de un programa legítimo, por lo que / kk

#include<bits/stdc++.h>
using namespace std ;
int n , m ;
const int maxn = 1e6 + 61 ;
vector < int > g[maxn] ;
int dep[maxn] , col[maxn] , fa[maxn] , vis[maxn] , ans[maxn] ;
int sq ;

void dfs(int u) {
    bool qwq = 1 ;
    for(int v : g[u]) {
        if(! dep[v]) {
            col[v] = col[u] ^ 1 ;
            fa[v] = u ;
            dep[v] = dep[u] + 1 ;
            dfs(v) ;
        }
        else {
            if(dep[u] < dep[v] && vis[v]) {
                qwq = 0 ;
            }
            if(dep[u] - dep[v] + 1 >= sq) {
                cout << 2 << '\n' ;
                cout << dep[u] - dep[v] + 1 << '\n' ;
                int now = u ;
                while(now ^ v) {
                    cout << now << ' ' ;
                    now = fa[now] ;
                }
                cout << now << '\n' ;
                exit(0) ;
            }
        }
    }
    vis[u] = qwq ;
    ans[col[u]] += qwq ;
}


void print(int c) {
    cout << 1 << '\n' ;
    for(int i = 1 ; i <= n ; i ++) 
        if(col[i] == c && sq && vis[i])
            cout << i << ' ' , sq -- ;
    exit(0) ;
}

int main() {
    ios :: sync_with_stdio(false) ;
    cin.tie(nullptr) , cout.tie(nullptr) ;
    cin >> n >> m ;
    sq = sqrt(n) ;
    if(sq * sq != n) ++ sq ;
    while(m --) {
        int u , v ;
        cin >> u >> v ;
        g[u].push_back(v);
        g[v].push_back(u) ;
    }
    dfs(dep[1] = 1) ;
    if(ans[0] >= sq) {
        print(0) ;
    }
    else {
        print(1) ;
    }
    return 0 ;
}

Supongo que te gusta

Origin www.cnblogs.com/Isaunoya/p/12505758.html
Recomendado
Clasificación