- Time: 2016-03-25-23:50:29
- Title Number: [2016-03-26][codeforces][632][a][grandma Laura and Apples]
- The main topic: There are n guests, each guest to buy half of the apples, if the apple is odd, the extra half of the apples to the guests, is known to buy a guest whether to receive more apples, ask how many dollars should be received in total
- Analysis:
- When the last Apple was left, the guest only bought half an apple and sent half an apple, so the last one must be plus,
- Direct calculation of the number of all apples, and the number of complimentary apples, the final total
#include <cstdio>
using namespace std;
typedef long long LL;
const int maxn = 50;
int a[maxn];
int main(){
int n,p;
char op[20];
scanf("%d%d",&n,&p);
for(int i = 0; i < n;++i){
scanf("%s",op);
a[i] = op[4] != ‘\0‘;
}
LL cnt = 0,bcnt = 0;
for(int i = n - 1;i >= 0 ;--i){
if(a[i]){
cnt = cnt * 2 + 1;
++bcnt;
}else{
cnt = cnt * 2;
}
}
printf("%I64d\n",cnt*p - bcnt * (p / 2));
return 0;
}
From for notes (Wiz)
[2016-03-26][codeforces][632][a][grandma Laura and Apples]