日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Educational Codeforces Round 9 A. Grandma Laura and Apples 水题

發布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Educational Codeforces Round 9 A. Grandma Laura and Apples 水题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A. Grandma Laura and Apples

題目連接:

http://www.codeforces.com/contest/632/problem/A

Description

Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.

She precisely remembers she had n buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.

So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).

For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is p (the number p is even).

Print the total money grandma should have at the end of the day to check if some buyers cheated her.

Input

The first line contains two integers n and p (1?≤?n?≤?40,?2?≤?p?≤?1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number p is even.

The next n lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift.

It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.

Output

Print the only integer a — the total money grandma should have at the end of the day.

Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Sample Input

2 10
half
halfplus

Sample Output

15

Hint

題意

有n個顧客買蘋果,每個蘋果p元

half就是這個顧客買了一半的蘋果

halfplus就是這個顧客買了一半蘋果,最后還送了他半個蘋果

最后恰好賣完所有蘋果

問你賺了多少錢

題解:

倒著推就好了

當成模擬題做就行了

代碼

#include<bits/stdc++.h> using namespace std;long long ans = 0; string s[45]; int main() {int n,p;scanf("%d%d",&n,&p);for(int i=0;i<n;i++)cin>>s[i];long long now = 0;for(int i=n-1;i>=0;i--){if(s[i]=="half"){ans+=now*p;now=now*2;}else{ans+=p/2+now*p;now=now*2+1;}}cout<<ans<<endl; } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Educational Codeforces Round 9 A. Grandma Laura and Apples 水题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。