CodeForces 632C Grandma Laura and Apples (模拟)

题意:有n个人买苹果,当苹果剩余偶数时买走一半,当苹果剩余奇数时,先买走一半,再用半价买走一个苹果,最终苹果恰好卖完.农民收入为多少.

析:反向模拟。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1;

typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){  return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}

string str[55];

int main(){
    while(scanf("%d %d", &n, &m) == 2){
        for(int i = 0; i < n; ++i)  cin >> str[i];
        LL ans = 0, x = 0;
        for(int i = n-1; i >= 0; --i){
            if(str[i].size() > 5){
                ans += x * m + m/2;
                x = x * 2 + 1;
            }
            else{
                ans += x * m;
                x *= 2;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
时间: 2024-08-26 14:19:18

CodeForces 632C Grandma Laura and Apples (模拟)的相关文章

[2016-03-26][codeforces][632][A][Grandma Laura and Apples]

时间:2016-03-25 23:50:29 星期五 题目编号:[2016-03-26][codeforces][632][A][Grandma Laura and Apples] 题目大意:有n的客人,每个客人都来买一半的苹果,如果苹果为奇数,就把多出来的半个苹果送给客人,已知买个客人是否收到更多苹果,问总共应该收到多少元 分析: 最后剩下一个苹果的时候,客人只买半个苹果,送半个苹果,所以最后一个一定是plus, 直接计算所有苹果的数目,和赠送的苹果数目,求最后总值 #include <cst

codeforces 632A A. Grandma Laura and Apples

A. Grandma Laura and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma

Educational Codeforces Round 9 -- A - Grandma Laura and Apples

题意: 外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了! 有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还会送半个苹果!问最多能赚多少钱? 思路: 会后一个人一定是halfplus,否则苹果卖不完,所以最后一个人买的时候已经只剩一个.然后从后往前推. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #

CF632A Grandma Laura and Apples

#include<bits/stdc++.h> using namespace std; long long n,p,ans=0,total=0,apple=0; int main() { string a[100000]; cin>>n>>p; p=p>>1; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=n;i>=1;i--) { total=total*2; if(a[i]==&q

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces 97D Robot in Basement bitset+模拟

题目链接:点击打开链接 题意: 每个点有一个机器人(.),下面是一些指令,每次发出指令(一个字母)所有机器人都会执行移动. 当机器人到E点就会离开. 若机器人前方是'#' 或者边界则停留原地.一个方格可以站多个机器人. bitset模拟.. #include <cstdio> #include <cstring> #include <algorithm> #include <bitset> using namespace std; char s[100005

Codeforces 12D Ball 树状数组模拟3个元素的排序

题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<a

codeforces 459C Pashmak and Buses(模拟,组合数A)

题目 跑个案例看看结果就知道了:8 2 3 题目给的数据是 n,k,d 相当于高中数学题:k个人中选择d个人排成一列,有多少种不同的方案数,列出其中n中就可以了. #include<iostream> #include<algorithm> #include<string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

Codeforces 309C Memory for Arrays 二进制模拟进位

题目链接:点击打开链接 题意: 给定n个箱子m个物品 下面n个数字表示箱子的容量 下面m个数字b1-bm 表示物品体积为2^bi大 问最多有多少个物品可以放入箱子. 思路: 贪心,先放小的,小的不能放再放大的 显然我们把n个箱子拆成二进制,然后模拟二进制减法运算. 剩下就是简单模拟 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<m