貪心(弱)已知當前排名,倒推上月排名

2021-07-16 18:53:16 字數 643 閱讀 2775

題意:給你n個當前排名的字串,和當前排名相對上個月的排名是上公升了還是下降了。求上個月的排名

解析:顯然。如果當前排名是up,那麼上個月的排名為[i + 1,n]。

如果是down ,那麼上個月的排名是[1,i - 1]

細思:貪心的做法就是按照i增加的順序讓down的盡量往前排(盡量不要占用後[t + 1,n]的區間),讓up也是盡量往前排。(下一次的i是更大的,不往前排就排不到了)

**:#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;

char s[106][106],d[106][10];

int id[106],ans[106];

bool vis[106];

int main()

}for(int i = 1; i <= n; i ++)}}

}for(int i = 1; i <= n; i ++)}}

}for(int i = 1; i <= n; i ++)

for(int i = 1; i <= n; i ++)

{// cout<

當弱引用物件成為集合元素時

當我們在系統用到某些占用記憶體較多的大物件,且該物件並不會被頻繁使 用 例如快取場景 時,考慮效能因素,或許我們可以選擇使用弱引用 weakreference 物件。弱引用物件就像是物件之中的 無間行者 行走於 活動 與 非活動 狀態之間。可能在某個時刻雖然對該物件存在引用,然而垃圾 器仍然可以對其...