笔记刷题-头条2018-06-02

2244 ワード

タイトル紹介:

/**
        ,            n        ——
        ,
         。
                ,
    ,          (     ),
      m          (           )。
         c 。
          n       ,                。
                   。
              m           。

    :
     n,m,c   ,     。
(1 <= n <= 10000, 1 <= m <= 1000, 1 <= c <= 50)
    n        num_i(0 <= num_i <= c)   i         。
        num_i   ,
     x   i       x   (1 <= x <= c)

    :
      ,                。

    1:
5 2 3
3 1 2 3
0
2 2 3
1 2
1 3

    1:
2

    1:
         1   ,      。
            1,3,4   , 3   4     ,      。
           1,3,5   , 5         1 ,      。
   2           。
   2       。
*/

考え方紹介:colorPosTable[c]はc番目の色が現れる位置を表す(時計回りに入力)
カラーセット記録色の種類
カラーセットを巡る様々な色
次に、colorPosTable[c]で1つのリングとして見られるpos 1 pos 2 pos 3が存在するかどうか、pos 1 pos 2 pos 3がリストに隣接する(タイミングニードル数)3つの下付き記号であるかどうかを見てから
int curLeft = (cur-1+sz)%sz;
int distLeft = abs(colorPosTable[color][cur]-colorPosTable[color][curLeft]);
(リング中の2点距離計算が短い部分)distLeft=min(distLeft,N-distLeft);
pos 2が左から右へpos 1 pos 3の距離がMより小さい場合、pos 2は問題の要求に合致する位置であり、カウンタに1を加算する.
コードは次のとおりです.

#include
#include
#include
#include

#define MAX_N 10005
#define MAX_M 1005
#define MAX_C 55

using namespace std;

//colorPosTable[c]   c        , colorPosTable[c]=0      (           )
vector colorPosTable[MAX_C];
set colorSet;

int main(){
    int N, M, C;
    scanf("%d%d%d", &N, &M, &C);
    for(int n=0; n::iterator it;
    for(it=colorSet.begin(); it!=colorSet.end(); it++){
        int color = (*it);
        int sz = colorPosTable[color].size();
        if(sz==1){
            continue;
        }
        for(int cur=0; cur