最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

CF344A - Magnets

2023-06-24 09:25 作者:您是打尖兒還是住店呢  | 我要投稿

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.


Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.


Input The first line of the input contains an integer n (1?≤?n?≤?100000) — the number of magnets. Then n lines follow. The i-th line (1?≤?i?≤?n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

------------------------------------------------------------

中文:

瘋狂科學(xué)家邁克通過排列多米諾骨牌來娛樂自己。 不過,他不需要多米諾骨牌:他使用矩形磁鐵。 每個磁鐵都有兩個極,正極(“正”)和負(fù)極(“減”)。 如果兩個磁鐵靠近放置在一起,那么同極會相互排斥,異極會相互吸引。


邁克首先將一塊磁鐵水平放在桌子上。 在接下來的每個步驟中,邁克都會在該行的右端水平添加一個磁鐵。 根據(jù)邁克將磁鐵放在桌子上的方式,它要么被前一個磁鐵吸引(形成一組連接在一起的多個磁鐵),要么被它排斥(然后邁克將這塊磁鐵放置在距前一個磁鐵右側(cè)一定距離的地方) 。 我們假設(shè)沒有與其他磁鐵相連的單個磁鐵形成了自己的一組。邁克將多個磁鐵排成一排。 確定磁鐵形成的組數(shù)。


輸入 輸入的第一行包含一個整數(shù) n (1?≤?n?≤?100000) — 磁鐵的數(shù)量。 然后是n行。 第 i 行 (1?≤?i?≤?n) 包含字符“01”(如果 Mike 將第 i 個磁鐵放在“正負(fù)”位置)或字符“10”(如果 Mike 將磁鐵放在“ 減-加”位置。

--------------------------------------

其實就是計算11或者00出線的次數(shù),出線多少次,那么就分成n+1次。輸出即可;

下面是代碼:


CF344A - Magnets的評論 (共 條)

分享到微博請遵守國家法律
安丘市| 玛纳斯县| 吕梁市| 武川县| 东阳市| 夏河县| 沛县| 荣昌县| 巴楚县| 温泉县| 金湖县| 松滋市| 剑河县| 黎川县| 同德县| 南皮县| 乐都县| 孙吴县| 彭泽县| 寿光市| 通海县| 昌邑市| 尼木县| 曲阜市| 甘肃省| 广宁县| 凤冈县| 遂川县| 闽侯县| 常熟市| 万年县| 东宁县| 山西省| 江北区| 邢台县| 贺兰县| 政和县| 台东县| 台安县| 隆尧县| 靖州|