牛客第二场Dmoney
链接: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的更多相关文章
- 牛客第二场A-run
链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 White Cloud is exercising in the playground. Wh ...
- 牛客第二场 J farm
White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The pl ...
- 牛客第二场-J-farm-二维树状数组
二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add( ...
- 牛客第二场 C.message(计算几何+二分)
题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d ...
- 第k小团(Bitset+bfs)牛客第二场 -- Kth Minimum Clique
题意: 给你n个点的权值和连边的信息,问你第k小团的值是多少. 思路: 用bitset存信息,暴力跑一下就行了,因为满足树形结构,所以bfs+优先队列就ok了,其中记录下最后进入的点(以免重复跑). ...
- 走环概率问题(至今有点迷)--牛客第二场( Eddy Walker)
思路: 概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include < ...
- 巅峰极客第二场CTF部分writeup
word-MISC 微信回答问题+word字体里. sqli-WEB 注册个admin空格即可,长字符截断. 晚上把后续的写出来.现在睡觉
- 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 把题目的矩阵看成无向图的邻接矩阵 这 ...
- 牛客CSP-S提高模拟4 赛后总结
前言 其实前面已经打了 3 场牛客 3 场计蒜客的比赛,都没有写总结,今天先提一下以前的情况 计蒜客 1 :0+0+0 = 0 (心态崩了,写挂了) 牛客 1: 0+0+0 = 0 (T1博弈论,T2 ...
随机推荐
- Echarts 设置地图大小
项目中要添加地图,默认地图太小,折腾半天终于找到解决方案. series: [ { //name: '香港18区人口密度', type: 'map', mapType: 'jiangsu', // 自 ...
- 项目Alpha冲刺--2/10
项目Alpha冲刺--2/10 1.团队信息 团队名称:基于云的胜利冲锋队 成员信息 队员学号 队员姓名 个人博客地址 备注 221500201 孙文慈 https://www.cnblogs.com ...
- QQ帐户的申请与登陆-(字符串操作)
题目: 实现QQ新帐户申请和老帐户登陆的简化版功能.最大挑战是:据说现在的QQ号码已经有10位数了. 输入格式: 输入首先给出一个正整数N(≤10^5),随后给出N行指令.每行指令的格式为:“命令符( ...
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile
完整的错误信息: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile ( ...
- 自定义 Git - 配置 Git
用git config配置 Git,要做的第一件事就是设置名字和邮箱地址: $ git config --global user.name "John Doe" $ git con ...
- Eclipse添加EGIT方法
1. 安装EGIT, 其中一个方法: 2. 新建javaweb项目,测试git的使用. l File > Team > Share Project 选择GIT 如何选择不了,则选择创建c ...
- TextView显示内容不全
今天开发遇到一个问题,发现TextView显示不全,很纳闷,看图: 正常情况应该是这个样子的: 造成这种情况的原因是: TextView被快速并且多次的设置内容值造成的. 我的场景: 我点击全选按钮, ...
- Vue 中 export及export default的区别
相信很多人都在vue使用过export.export default.import,然而它们到底有什么区别呢? 在ES6中,export与export default均可用于导出常量.函数.文件.模块 ...
- springmvc如何进行热部署开发
1.场景还原 在工程量大的情况下,tomcat运行部署一次会花费相当多的时间,这样太 浪费人力以及时间了:今天笔者将 讲解一下如何配置springmvc工程的热部署 2.实现方案 其实很简单! ①在t ...
- 雷林鹏分享:jQuery EasyUI 树形菜单 - 创建带复选框的树形菜单
jQuery EasyUI 树形菜单 - 创建带复选框的树形菜单 easyui 的树(Tree)插件允许您创建一个复选框树.如果您点击一个节点的复选框,这个点击的节点信息将向上和向下继承.例如:点击 ...