链接: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. Spring3.x 版本和 JDK1.8 不兼容导致 java.lang.IllegalStateException: Failed to load ApplicationContext

    由于安装了 JDK1.8 的版本,最近在进行整合 Struts2+Spring+Hibernate 框架的时候,不小心导入了之前下载的 Spring 3.2.0 版本的 jar 包. 结果在运行测试用 ...

  2. Perl中命令行参数以及打开管道文件

    打开管道文件   Linux提供了管道机制,可以方便应用程序之间的数据传递.在Perl中,扣开和使用管道可采用如下形式的open函数:   open(Filehandle,”丨 CMD”);   其中 ...

  3. React native 之设置IOS的图标,名称和启动图(下篇文章会讲到RN的android的相关设置)

    1.首先,app的名称: 如图所示:我的工程名叫BOOk 在BOOk下面的info.plist的文件里设置app的相关信息:比如Bundle name就是设置APP的名称 2.App的图标:(这里注意 ...

  4. L2-019. 悄悄关注

    说真的,看了一些L2题明白多学点库函数是多么重要!!!! 会map这题直接水过,map用法不解释自己学,代码如下: #include<bits/stdc++.h> using namesp ...

  5. Maven命令行创建java或javaWeb项目

    Maven命令行创建java或javaWeb项目   1.命令行创建普通java项目 mvn archetype:generate -DgroupId=com.fxust -DartifactId=d ...

  6. [JS]计算字符串中出现最多的字符和其出现次数

    这是一道面试题 此处是利用Obj来解决的,当然不只此一种方法. //思路:遍历数组,拿到一个字符,并将之以 "字符":出现次数 的key:value形式存到对象中. //如果此字符 ...

  7. HTML 标记 3 —— CSS

    <style type="text/css">body { background-color: #F00;} p{ color:#0F0; } .自己定义 { colo ...

  8. LeetCode第[20]题(Java):Valid Parentheses

    题目:有效的括号序列 难度:Easy 题目内容: Given a string containing just the characters '(', ')', '{', '}', '[' and ' ...

  9. maven配置环境变量失败解决办法

    配置maven路径什么的统统正确,最后测hi不成功.在网上搜索了好多资料方法都解不了 具体问题具体对待吧,如果有和我类似的小伙伴,可以尝试一下我的这个办法,在maven路径后面加/bin path变量 ...

  10. git stash命令

    命令:git stash 1.使用git stash 保存当前的工作现场, 那么就可以切换到其他分支进行工作,或者在当前分支上完成其他紧急的工作,比如修订一个bug测试提交. 2.如果一个使用了一个g ...