链接:https://www.nowcoder.com/acm/contest/140/D
来源:牛客网 题目描述
White Cloud has built n stores numbered from to n.
White Rabbit wants to visit these stores in the order from to n.
The store numbered i has a price a[i] representing that White Rabbit can spend a[i] dollars to buy a product or sell a product to get a[i] dollars when it is in the i-th store.
The product is too heavy so that White Rabbit can only take one product at the same time.
White Rabbit wants to know the maximum profit after visiting all stores.
Also, White Rabbit wants to know the minimum number of transactions while geting the maximum profit.
Notice that White Rabbit has infinite money initially.
输入描述:
The first line contains an integer T(<T<=), denoting the number of test cases.
In each test case, there is one integer n(<n<=) in the first line,denoting the number of stores.
For the next line, There are n integers in range [,), denoting a[..n].
输出描述:
For each test case, print a single line containing integers, denoting the maximum profit and the minimum number of transactions.
示例1
输入
复制 输出
复制

贪心。下一家店变贵了手里没有拿就买。下一家店便宜了,手里有货就卖出。

 #include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
using namespace std;
#define ll long long
int a[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m;
scanf("%d",&m);
for(int i=;i<=m;i++)
{
scanf("%d",&a[i]);
}
ll flag=;
ll ans=;
ll mo=;
a[m+]=;
for(int i=;i<=m;i++)
{
if(a[i]<a[i+]&&flag==)
{
flag=;
ans++;
mo=mo-a[i];
}
else
{
if(flag==&&a[i]>a[i+])
{
ans++;
flag=;
mo=mo+a[i];
}
}
}
cout<<mo<<" "<<ans<<endl; }
return ;
}

牛客第二场Dmoney的更多相关文章

  1. 牛客第二场A-run

    链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 White Cloud is exercising in the playground. Wh ...

  2. 牛客第二场 J farm

    White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The pl ...

  3. 牛客第二场-J-farm-二维树状数组

    二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add( ...

  4. 牛客第二场 C.message(计算几何+二分)

    题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d ...

  5. 第k小团(Bitset+bfs)牛客第二场 -- Kth Minimum Clique

    题意: 给你n个点的权值和连边的信息,问你第k小团的值是多少. 思路: 用bitset存信息,暴力跑一下就行了,因为满足树形结构,所以bfs+优先队列就ok了,其中记录下最后进入的点(以免重复跑). ...

  6. 走环概率问题(至今有点迷)--牛客第二场( Eddy Walker)

    思路: 概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include < ...

  7. 巅峰极客第二场CTF部分writeup

    word-MISC 微信回答问题+word字体里. sqli-WEB 注册个admin空格即可,长字符截断. 晚上把后续的写出来.现在睡觉

  8. uestc summer training #4 牛客第一场

    A dp[i][j][k]可以n3地做 但是正解是找把问题转化为一个两点不相交路径 最终答案为C(n+m, n)2-C(n+m, m-1)C(n+m,n-1) B 把题目的矩阵看成无向图的邻接矩阵 这 ...

  9. 牛客CSP-S提高模拟4 赛后总结

    前言 其实前面已经打了 3 场牛客 3 场计蒜客的比赛,都没有写总结,今天先提一下以前的情况 计蒜客 1 :0+0+0 = 0 (心态崩了,写挂了) 牛客 1: 0+0+0 = 0 (T1博弈论,T2 ...

随机推荐

  1. JqGrid 自定义子表格 及 自定义Json 格式数据不展示

    项目第一次使用JqGrid ,发现功能强大,但由于对他不熟悉,也没有少走弯路,记录一下. 1.引用 <link href="~/Scripts/JqGrid/jqgrid/css/ui ...

  2. 如何终止线程的运行(C/C++)

    想要终止线程的运行,可以使用以下方法: 1.线程函数返回(最好使用该方法). 2.通过调用ExitThread函数,线程将自行撤消(最好不使用该方法). 3.同一个进程或另一个进程中的线程调用Term ...

  3. 初步接触ES6

    Babel---ES6转码器 ES6 声明变量的六种方法 ES5 只有两种声明变量的方法:var命令和function命令. ES6除了添加let和const命令,另外两种声明变量的方法:import ...

  4. 因样式冲突引起的div消失问题

    工作需要,搭建一个网站的模型,简单分成三个部分,标题栏,导航栏,主界面,效果如图: 但是点击界面的任意地方,中间的div块消失了,如图所示: 调试,发现在点击界面其他地方的时候display属性有变化 ...

  5. 在浏览器端用es6,babel+browserify打包

    写得最清楚的是这个系列: 一个普通的写网页的人如何过渡到ES6 (一) 感觉比babel官网写得还清楚点. 看完这个才有点理解node原来不只是用来起express后端web server,更主要用途 ...

  6. 用友软件系统管理员账号admin密码忘记了,如何解决?

    1.打开数据库. 2.点开  数据库-UFSystem. 3.找到dbo.UA_user表,鼠标右键,点打开表. 4.打开后,找到admin,cPassword列即可找到系统管理员密码.

  7. Unity --- 纹理压缩基本知识点

    1.Unity支持的压缩格式的分类,这里主要指Android平台和IOS平台: DXT格式 --- Nvidia Tegra(图睿)提供ETC  --- 安卓原生支持的,OPNEGL2.0都支持,ET ...

  8. Asp.net core 学习笔记 (操作 url and query params)

    更新 :2018-7-25 直接添加 query string. var resetPasswordLink = QueryHelpers.AddQueryString($"{Request ...

  9. nginx反向代理实例

    通过一个例子演示一下nginx是如何代理服务的,并且讲一下nginx.conf的关于server模块和location模块的配置 server模块:配置虚拟主机的相关参数,一个http中可以有多个se ...

  10. Windows 下 Redis 服务无法启动,错误 1067 进程意外终止解决方案

    1.检查端口是否被占用 2.修改 Windows 服务里的 Redis 服务为本地系统服务(修改方式见下文) 方法: 1.看系统日志 桌面计算机/此电脑(Win10名称)右键打开管理,或 Win+R ...