题目倒是不难,可是读起来非常恶心

依据题目的描写叙述不easy找到适合存储的方法

后来我就想不跟着出题人的思路走

我自己开一个数组c

令c[a[i]] = b[i]

则c[i] == [j] 代表第i天相应有j个果子成熟

接着用贪心的方法做就好了

当前天尽可能收取昨天的果子。在收完的情况下再考虑今天的果子

代码例如以下:

#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 10010
#define ll long long
using namespace std; int c[MAXN];
int a, b;
ll t, v, n, ans; void f(int i) { if(c[i] && t) {
if(c[i] > t) {
ans += t;
c[i] -= t;
t = 0;
}
else {
ans += c[i];
t -= c[i];
c[i] = 0;
}
}
} int main(void) { while(cin >> n >> v) {
ans = 0;
for(int i=1; i<=n; ++i) {
cin >> a >> b;
c[a] += b;
}
for(int i=1; i<3005; ++i) {
t = v;
f(i-1);
f(i);
// f(i+1);
}
cout << ans << endl;
}
return 0;
}

Codeforces #252 (Div. 2) B. Valera and Fruits的更多相关文章

  1. Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)

    B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #252 (Div. 2) B. Valera and Fruits

    #include <iostream> #include <vector> #include <algorithm> #include <map> us ...

  3. Codeforces Round #252 (Div. 2) 441B. Valera and Fruits

    英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...

  4. codeforces Round #252 (Div. 2) C - Valera and Tubes

    贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...

  5. Codeforces Round #252 (Div. 2) A - Valera and Antique Items

    水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...

  6. Codeforces Round 252 (Div. 2)

    layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  7. Codeforces 441 B. Valera and Fruits

    B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  9. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

随机推荐

  1. flask开发restful api

    flask开发restful api 如果有几个原因可以让你爱上flask这个极其灵活的库,我想蓝图绝对应该算上一个,部署蓝图以后,你会发现整个程序结构非常清晰,模块之间相互不影响.蓝图对restfu ...

  2. 积累的VC编程小技巧之框架窗口及其他

    1.修改主窗口风格 AppWizard生成的应用程序框架的主窗口具有缺省的窗口风格,比如在窗口标题条中自动添加文档名.窗口是叠加型的.可改变窗口大小等.要修改窗口的缺省风格,需要重载CWnd::Pre ...

  3. “ASP.default_aspx”并不包括“DropDownList1_SelectedIndexChanged”的定义,其解决方法。

    "ASP.default_aspx"并不包括"DropDownList1_SelectedIndexChanged"的定义,其解决方法. 在使用DropDown ...

  4. winDbg 命令使用帮助

    srv*C:/symbol*http://msdl.microsoft.com/download/symbols;D:\Desktop\CMS_Dump symck //检查pdblm //显示pdb ...

  5. GotGitHub — GotGitHub

    GotGitHub - GotGitHub GotGitHub

  6. Android installed app, never used, cannot receiver BroadcastReceiver

    官方文档是这么写的:(http://developer.android.com/about/versions/android-3.1.html#launchcontrols) Launch contr ...

  7. Nginx之http_image_filter_module模块使用

    一.安装 #yum install gd-devel # #./configure --prefix=/usr/local/nginx \ # --with-debug \ # --with-http ...

  8. leetcode第一刷_Largest Rectangle in Histogram

    非常难的问题,数组线性时间. 属于我之前说的解法的借助辅助空间.给定两个柱子,他们之间的面积由什么确定呢?没错,他们之间的距离和他们之间最矮的那个柱子的高度.我们并不知道这个柱子在什么位置,所以仅仅能 ...

  9. 深入 理解 Statement 和 PreparedStatement

    一.使用Statement而不是PreparedStatement对象 JDBC驱动的最佳化是基于使用的是什么功能. 选择PreparedStatement还是Statement取决于你要怎么使用它们 ...

  10. Java-WebSocket 项目的研究(三) WebSocketClient 类 具体解释

    通过之前两篇文章 Java-WebSocket 项目的研究(一) Java-WebSocket类图描写叙述 Java-WebSocket 项目的研究(二) 小试身手:client连接server并发送 ...