1. 程式人生 > >topcoder srm 615 div1

topcoder srm 615 div1

problem1 link

對於數字$x$,檢驗每個滿足$x=y*2^{t}$的$y$能否變成$x$即可。

problem2 link

如果起點到終點有一條長度為$L$的路徑,那麼就存在長度為$L+kR$的路徑。其中$R$為從路徑上某點轉一圈再回到這一點的環的長度。

為了保證總是存在這個環,可以令這個環為從起點出發再回到起點。所以如果有一條長度為$d$的邊$0\rightarrow t$,那麼可以令$R=2d$,即$0\rightarrow t \rightarrow 0$.

只需要記錄起點到達某個點長度模$R$的最短路即可。即用$f[m][u]$表示從0到$u$的最小的滿足$m+kR$的路徑長度。

只要$f[T$%$R][N-1] \leq T$即可。

problem3 link

紅色和綠色需要配對出現。所以可以將一個紅色一個綠色看作一個整體。那麼就是$M$組中每組要出現$D$個配對的整體。

從前向後進行動態規劃,只統計出現了多少個配對的整體以及還有多少個只配對了一半的。

這裡有個問題是每一組中的$D$個整體不能交叉出現。為了做到這一點,只需要配對了一半的個數不超過$M$即可.

code for problem1

#include <set>
#include <vector>

class AmebaDiv1 {
 public:
  int count(const std::vector<int> &X) {
    auto Get = [&](int t) {
      for (auto e : X) {
        if (e == t) {
          t *= 2;
        }
      }
      return t;
    };

    std::set<int> all(X.begin(), X.end());
    int result = 0;
    for (auto e : all) {
      bool tag = (Get(1) != e);
      int t = e;
      while (t > 1) {
        if (Get(t) == e) {
          tag = false;
          break;
        }
        t /= 2;
      }
      if (tag) {
        ++result;
      }
    }

    return result;
  }
};

code for problem2

#include <cstring>
#include <set>
#include <string>
#include <vector>

constexpr int MAXD = 20000;
constexpr int MAXN = 50;

long long dist[MAXD][MAXN];

class LongLongTripDiv1 {
 public:
  std::string isAble(int N, const std::vector<int> &A,
                     const std::vector<int> &B, const std::vector<int> &D,
                     long long T) {
    int n = static_cast<int>(A.size());
    int d = MAXD + 1;
    for (int i = 0; i < n; ++i) {
      if (A[i] == 0 || B[i] == 0) {
        d = std::min(d, D[i]);
      }
    }

    if (d == MAXD + 1) {
      return "Impossible";
    }

    std::set<std::pair<long long, std::pair<int, int>>> que;
    memset(dist, -1, sizeof(dist));
    auto Insert = [&](long long dis, int u, int v) {
      auto iter = que.find({dist[u][v], {u, v}});
      if (iter != que.end()) {
        que.erase(iter);
      }
      que.insert({dis, {u, v}});
      dist[u][v] = dis;
    };
    Insert(0, 0, 0);
    while (!que.empty()) {
      auto node = que.begin()->second;
      que.erase(que.begin());
      int u = node.second;
      for (int i = 0; i < n; ++i) {
        if (A[i] != u && B[i] != u) {
          continue;
        }
        int v = A[i] + B[i] - u;
        int t = (node.first + D[i]) % (2 * d);
        long long new_dist = dist[node.first][u] + D[i];
        if (dist[t][v] == -1 || new_dist < dist[t][v]) {
          Insert(new_dist, t, v);
        }
      }
    }
    auto min_dist = dist[T % (d * 2)][N - 1];
    return (min_dist != -1 && min_dist <= T) ? "Possible" : "Impossible";
  }
};

code for problem3

#include <string>

constexpr int MOD = 1000000007;

int f[5005][50][51];

class AlternativePiles {
 public:
  int count(const std::string &C, int M) {
    if (Red(C[0])) {
      f[0][0][1] += 1;
    }
    if (Blud(C[0])) {
      f[0][0][0] += 1;
    }
    for (size_t idx = 1; idx < C.size(); ++idx) {
      char c = C[idx];
      for (int x = 0; x < M; ++x) {
        for (int y = 0; y <= M; ++y) {
          int t = f[idx - 1][x][y];
          if (t == 0) {
            continue;
          }
          if (Red(c) && y + 1 <= M) {
            (f[idx][x][y + 1] += t) %= MOD;
          }
          if (Blud(c)) {
            (f[idx][x][y] += t) %= MOD;
          }
          if (Green(c) && y > 0) {
            (f[idx][(x + 1) % M][y - 1] += t) %= MOD;
          }
        }
      }
    }
    return f[C.size() - 1][0][0];
  }

 private:
  bool Red(char c) { return c == 'R' || c == 'W'; }

  bool Green(char c) { return c == 'G' || c == 'W'; }

  bool Blud(char c) { return c == 'B' || c == 'W'; }
};

相關推薦

topcoder srm 615 div1

problem1 link 對於數字$x$,檢驗每個滿足$x=y*2^{t}$的$y$能否變成$x$即可。 problem2 link 如果起點到終點有一條長度為$L$的路徑,那麼就存在長度為$L+kR$的路徑。其中$R$為從路徑上某點轉一圈再回到這一點的環的長度。 為了保證總是存在這個環,可以令這個

Topcoder SRM 603 div1題解

大於 並不是 roo swa ndb mod 我們 連接 字母 昨天剛打了一場codeforces。。。困死了。。。不過趕在睡前終於做完了~ 話說這好像是我第一次做250-500-1000的標配耶~~~ Easy(250pts): 題目大意:有一棵樹,一共n個節點,每個節點

Topcoder SRM 604 div1題解

cond 代碼 簡單 let min oge 這樣的 swe possible CTSC考完跑了過來日常TC~~~ Easy(250pts): 題目大意:有個機器人,一開始的位置在(0,0),第k個回合可以向四個方向移動3^k的距離(不能不動),問是否可以到達(x,y),數

Topcoder SRM 608 div1 題解

b+ 輸出 har 不能 include c++ point pac easy Easy(300pts): 題目大意:有n個盒子,一共有S個蘋果,每個盒子有多少個蘋果不知道,但是知道每個盒子的蘋果下限和上限。現在要至少選擇X個蘋果,問如果要保證無論如何都能獲得至少X個蘋果,

Topcoder SRM 722 Div1 600Pts DominoTiling(簡單插頭DP)

lap 就是 ont 要求 net esp $1 true mes 題意 給定一個$12*12$的矩陣,每個元素是‘.‘或‘X‘。現在要求$1*2$的骨牌鋪滿整個矩陣, ‘X‘處不能放置骨牌。求方案數。 這道題其實和 Uva11270 是差不多

Topcoder SRM 675 Div1 500Pts LimitedMemorySeries1(分塊)

tor bits fin get pre n) ted 多少 top 題意 給定一個長度不超過$5*10^{6}$的數列和不超過$100$個詢問,每次詢問這個數列第$k$小的數,返回所有詢問的和    內存限制很小,小到不能存下這個數列。(數列以種子的形式給出)   

TopCoder SRM 682 Div1 Problem 450 SuccessfulMerger (環套樹 + 分類討論)

特殊 com 新的 比較 -- ace info cpp ear 題意 給定一個$n$個點$n$條邊的無向圖,現在要把這個圖進行若幹次操作,並選擇一個點作為首都。    要求除首都外的任意兩個點$u$, $v$,從$u$走到$v$必須經過這個首都。 操

topcoder srm 738 div1 FindThePerfectTriangle(枚舉)

desc cond 問題 pub ack info win continue multiple Problem Statement You are given the ints perimeter and area. You

Topcoder SRM 563 Div1 500 SpellCards

就是 bit its () 技能 push 背包 一個 max 題意 [題目鏈接]這怎麽發鏈接啊。。。。。 有\(n\)張符卡排成一個隊列,每張符卡有兩個屬性,等級\(li\)和傷害\(di\)。 你可以做任意次操作,每次操作為以下二者之一: 把隊首的符卡移動到隊尾。 使用

topcoder srm 625 div1

problem1 link 假設第$i$種出現的次數為$n_{i}$,總個數為$m$,那麼排列數為$T=\frac{m!}{\prod_{i=1}^{26}(n_{i}!)}$ 然後計算迴文的個數,只需要考慮前一半,得到個數為$R$,那麼答案為$\frac{R}{T}$. 為了防止數字太大導致越界,可以

[題解]TopCoder SRM 625 div1 T1 PalindromePermutations

哇塞今天居然做出來了兩道TC哎~(≧▽≦)/~(好像這是什麼值得高興的事情一樣) 題目描述 給出一個字串s,問把s中的字元打亂後得到迴文串的概率是多少(|s|<=50) 分析 哎呀又是自己想出來的可開心啦 首先我們不考慮精度問題,先計算出打亂之後的所有可能字串

topcoder srm 630 div1

problem1 link 首先計算任意兩點的距離。然後列舉選出的集合中的兩個點,判斷其他點是否可以即可。 problem2 link 假設字串為$s$,長度為$n$。那麼對於$SA$中的兩個排名$SA_{i},SA_{i+1}$來說,應該儘量使得$s[SA_{i}]=s[SA_{i+1}]$。如果這個

TopCoder SRM 568 Div1 500 EqualSums

這題可以說是花了一個多月才解決(霧 暑假的時候就很認真想過了,就是差了一步,昨天突然開竅。 emmm我真棒 我們發現題目的條件可以轉化為對於任意a[i][j]=a[i][1]+a[1][j]−a[1][1](i&gt;1,j&gt;1)a[i][

topcoder srm 640 div1

problem1 link 首先使用兩個端點顏色不同的邊進行連通。答案是$n-1-m$。其中$m$是聯通分量的個數。 problem2 link 首先構造一個最小割的模型。左邊的$n_{1}$個點與源點相連,右邊的$n_{2}$個點與匯點相連。每個中間點最少有$d+1$條邊(有一條到匯點/源點的邊)。最

TopCoder SRM 666 Div1 444 SumOverPermutations

感覺是道好題~TC好多題就這樣,想半天,然後程式碼幾行就完了。 原來碰到這種排列的dp就一臉懵逼,因為狀態特別難設計,每次都感覺只會狀壓,現在終於有點get到其中的套路了。 在這題裡我們可以發現幾個事實 每個位置對答案的貢獻只和它左右兩邊是否比它早確定有關 我

TopCoder SRM 681 Div1 500 LimitedMemorySeries2

這題假得不行啊…一直感覺O(nlogn)O(nlogn)O(nlogn)是過不了的,結果TC評測機太強了啊,1e7的資料200+ms就跑過去了。。所以說要有信仰啊。。。 好的其實這題就是純暴力,複雜度證明我就直接從網上粘一個過來了。。 Let’s look a

TopCoder SRM 712 Div1 600 AverageVarianceSubtree

卡精度沒素質。。。。 今天才知道有__float128這種東西,問了一下noip不能用。。。 DescriptionDescriptionDescription 傳送門 nnn個點的樹,每個點有一個權值,任選一棵非空子樹,求其中所有點方差的期望。 Solutio

topcoder srm 575 div1

problem1 link 如果$k$是先手必勝那麼$f(k)=1$否則$f(k)=0$ 通過對前面小的數字的計算可以發現:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其他情況都是1 這個可以用數學歸納法證明 problem2 link 假設字串的總長度為$n$ 首先

topcoder srm 610 div1

problem1 link  計算每個格子向上的最大高度。然後每個格子同一行前面的格子以及當前格子作為選取的矩形的最後一行,計算面積並更新答案。 problem2 link 對於兩個資料$(x_{1},y_{1}),(x_{2},y_{2})$,若先完成第一個再完成第二個,那麼一開始的值$F$需要滿足$

topcoder srm 630 div1 (2-SAT and SCC template)

#include <algorithm> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> class Stro