【Henu ACM Round #12 A】 Grandma Laura and Apples
and 12 round ACM Henu
2023-09-14 09:03:45 时间
【链接】 我是链接,点我呀:)
【题意】
【题解】
知道题意之后就是一个模拟的过程了。 用int now记录当前苹果的个数。bool flag记录是否有小数(即半个苹果) (这样处理为了防止double精度误差 根据half 和halfplus的规则,变化now和flag即可。 变的时候把卖出去的苹果累加答案【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 40;
int n,p;
string s[N+10];
ll ans = 0;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> p;
for (int i = 1;i <= n;i++){
cin >> s[i];
}
ll now = 0,flag = 0;
for (int i = n;i >=1;i--){
string temp = s[i];
if (temp!="half"){
if (flag==0){
flag = 1;
}else{
flag = 0;
now++;
}
ans += 1LL*now*p;
now*=2;
if (flag){
ans+=p/2;
now++;
flag = 0;
}
}else{
ans+=1LL*now*p;
now*=2;
if (flag){
ans+=p/2;
now++;
flag = 0;
}
}
}
cout << ans << endl;
return 0;
}
相关文章
- Fine-tuning Convolutional Neural Networks for Biomedical Image Analysis: Actively and Incrementally如何使用尽可能少的标注数据来训练一个效果有潜力的分类器
- [Schematics] 1. Copy and Manipulate Template
- [Angular] Zones and NgZone
- [Javascript] Combine Objects with Object.assign and Lodash merge
- [Spring boot] CommandLineRunner and Autowired
- [Typescript Kaop-ts] Use AOP in Vue Components with TypeScript and Kaop-ts
- [RxJS] Connection operator: multicast and connect
- [Angular 2] Using ngrx/store and Reducers for Angular 2 Application State
- 【Henu ACM Round#20 D】 Devu and Partitioning of the Array
- hdu 5417 Victor and Machine