CodeForces1208A&B

女爷i 2023-06-02 11:56 144阅读 0赞

CodeForces1208A

不得不承认,这题猛地一看吓到我了,吓得我直接看了\(B\)题,要不是\(B\)也吓到我了我就直接做\(B\)了.

打打表,找一找,你会发现,这玩意三个一循环,所以就只需要算\(f_0,f_1,f_2\)就完了,输出\(f_{n \% 3}\).

完美解决.

CodeForces1208B

由于\(A\)实在太水了,所以我打算这两道题放在一起.
不得不承认,这题也吓到我了,这直接导致我滚回去做\(A\)了.
其实也并不难,这题一般都能想到二分区间长度,然后枚举左端点,把这一部分硬拆出来判断,用桶记录就行了.
但是这题的症结在于开桶的话空间是负担不起的.
但我们发现,尽管值域很广,但是不同的数字地个数并不会超过\(n\),而\(n\)的数量级是\(10^3\)级别的,所以我们直接离散化就好了.

\(Code:\)

  1. #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 ; }

转载于:https://www.cnblogs.com/Equinox-Flower/p/11447148.html

发表评论

表情:
评论列表 (有 0 条评论,144人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CF1208C

    CF1208C > 这场杜老师大战tourist的比赛怎么这么多人类智慧题。。。 题意: > 构造一个 $ n \\times n $ 的矩阵,使得该矩阵...

    相关 CF1208D

    CF1208D 题意; > 给你一个数组,要求支持单点修改和单点查询 解法: > 直接线段树搞一搞就没了。 CODE: includ...

    相关 CodeForces1208C

    CodeForces1208C 常见的构造题,这题的要求就给我一种疯狂暗示你按位构造的感觉,所以我一开始就疯狂尝试按位构造,但是...这时,\\(dalao\\)画了一张

    相关 CodeForces1208D

    CodeForces1208D 也是挺吓人的一道题,我一开始以为给的是每个数字前比它小的数字有几个,然后我就苦苦看不懂样例... 然后我冷静了一下,重新分析,读题,发现

    相关 CodeForces1208A&B

    CodeForces1208A 不得不承认,这题猛地一看吓到我了,吓得我直接看了\\(B\\)题,要不是\\(B\\)也吓到我了我就直接做\\(B\\)了. 打打表,找

    相关 1208: 战地冲锋

    题目描述 话说辽军与MCA相峙多年,终于在一个秋日的早晨爆发了一次大规模的冲突.情况是这样子的,当天上午,由耶律-Pacision领军的辽军忽然带领数万人马浩浩荡荡向MC