CodeForces1208A&B

CodeForces1208A

Have to admit, this question first glance scared me, scared I looked directly \ (B \) problem, either \ (B \) also scares me. I'll just do \ (B \) a .

Playing table, look, you will find that a thing three cycles, so we need only count \ (f_0, f_1, f_2 \ ) would be finished, output \ (n-F_ {\%}. 3 \) .

Perfect solution.

CodeForces1208B

Since \ (A \) is too water, so I'm going to put these two questions together.
Have to admit, this question also scared me, which led directly to I go back to do \ (A \) a.
In fact, not difficult, this problem can usually expect partition between two lengths, then enumerate the left point, put the hard part out of the split judgment, with a barrel record on the line.
but the crux of this problem is that the barrel is open if space is unaffordable.
However, we found that although the range is very wide, but a different number of digits to and no more than \ (n \) , and \ (n \) magnitude is \ (10 ^ 3 \) level, so we direct discrete of the fine.

\(Code:\)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
#define per(i,a,b) for (int i = a ; i >= b ; -- i)
#define pii pair < int , int >
#define X first
#define Y second
#define rint read<int>
#define int long long
#define pb push_back
#define mid ( ( l + r ) >> 1 )
 
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
 
template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
        while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
   return f * x ;
}
 
const int N = 2e3 + 100 ;
 
int n , l , r , ans = 0x3f3f3f3f , val[N] , idx ;
bool f , mk[N] ;
 
struct pairs { int data , pos ; } v[N] ;
 
inline bool check (int d) {
    for (int i = 1 ; i <= n - d + 1 ; ++ i){
        f = true ; MEM ( mk , 0 ) ;
        for (int j = 1 ; j < i && f ; ++ j) if ( mk[val[j]] ) f = false ;
        else mk[val[j]] = true ; if ( ! f ) continue ;
        for (int j= i + d ; j <= n && f ; ++ j) if ( mk[val[j]] ) f = false ;
        else mk[val[j]] = true ; if ( f ) return true ;
    }
    return false ;
}
 
inline bool cmp (pairs a , pairs b) {
    if ( a.data != b.data ) return a.data < b.data ;
    else return a.pos < b.pos ;
}
 
signed main () {
    n = rint () ;
    rep ( i , 1 , n ) { v[i].data = rint () ; v[i].pos = i ; } r = n - 1 ;
    std::sort ( v + 1 , v + n + 1 , cmp ) ; idx = 0 ;
    rep ( i , 1 , n )
        if ( v[i].data != v[i-1].data ) val[v[i].pos] = ++ idx ;
        else val[v[i].pos] = idx ;
    while ( l <= r ) {
        if ( check ( mid ) ) ans = mid , r = mid - 1 ;
        else l = mid + 1 ;
    }
    printf ("%I64d\n" , ans ) ; // I64d是因为CF只支持这玩意儿,不支持lld
    return 0 ;
}

Guess you like

Origin www.cnblogs.com/Equinox-Flower/p/11447148.html