1. 链接:https://www.nowcoder.com/acm/contest/140/D
  2. 来源:牛客网
  3.  
  4. 题目描述
  5. White Cloud has built n stores numbered from to n.
  6. White Rabbit wants to visit these stores in the order from to n.
  7. 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.
  8. The product is too heavy so that White Rabbit can only take one product at the same time.
  9. White Rabbit wants to know the maximum profit after visiting all stores.
  10. Also, White Rabbit wants to know the minimum number of transactions while geting the maximum profit.
  11. Notice that White Rabbit has infinite money initially.
  12. 输入描述:
  13. The first line contains an integer T(<T<=), denoting the number of test cases.
  14. In each test case, there is one integer n(<n<=) in the first line,denoting the number of stores.
  15. For the next line, There are n integers in range [,), denoting a[..n].
  16. 输出描述:
  17. For each test case, print a single line containing integers, denoting the maximum profit and the minimum number of transactions.
  18. 示例1
  19. 输入
  20. 复制
  21.  
  22. 输出
  23. 复制

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

  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. #include <iomanip>
  5. #include <cmath>
  6. #include <cstdlib>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <map>
  10. #include <queue>
  11. #include <vector>
  12. #include <set>
  13. #include <stack>
  14. using namespace std;
  15. #define ll long long
  16. int a[];
  17. int main()
  18. {
  19. int T;
  20. scanf("%d",&T);
  21. while(T--)
  22. {
  23. int m;
  24. scanf("%d",&m);
  25. for(int i=;i<=m;i++)
  26. {
  27. scanf("%d",&a[i]);
  28. }
  29. ll flag=;
  30. ll ans=;
  31. ll mo=;
  32. a[m+]=;
  33. for(int i=;i<=m;i++)
  34. {
  35. if(a[i]<a[i+]&&flag==)
  36. {
  37. flag=;
  38. ans++;
  39. mo=mo-a[i];
  40. }
  41. else
  42. {
  43. if(flag==&&a[i]>a[i+])
  44. {
  45. ans++;
  46. flag=;
  47. mo=mo+a[i];
  48. }
  49. }
  50. }
  51. cout<<mo<<" "<<ans<<endl;
  52.  
  53. }
  54. return ;
  55. }

牛客第二场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. _itemmod_enchant_groups

    随机附魔组 附魔组 `groupId` 分组编号,同一groupId的附魔效果被随机抽取 `enchantId` 附魔Id 对应SpellItemEnchantment.dbc `chance` 被抽 ...

  2. 宠物属性控制_pet

    classIndex 职业索引 DmgAddPct 根据职业的法伤或攻强来计算宠物增加的物理伤害,增加的伤害值等于玩家法伤或攻强的百分比 SpAddPct 根据职业的法伤或攻强来计算宠物增加的法术伤害 ...

  3. Mysql 函数使用记录(一)——DATEDIFF、CONCAT

    当目前为止呢,个人对Mysql的函数没有进行过统一的学习使用,都是用到了再去学习.而近日开始学习Linux了,所以为了防止这段时期结束后,将此阶段期间遇到的Mysql函数遗忘,开始在此对其做一个简单的 ...

  4. JS实现 进度条 不用控件

    demo1 <html> <head> <title>进度条</title> <style type="text/css"&g ...

  5. STL_string.【转】C++中int、string等常见类型转换

    ZC:#include <sstream> ZC:貌似还有 istringstream 和 ostringstream ... https://www.cnblogs.com/gaobw/ ...

  6. 构造函数中用:base

    如果person中有自己写的构造函数 则Student类的构造方法必须要加:base继承这个构造方法!因为默认的Student:base(空)构造方法已经被干掉了 构造方法的调用//base里的参数, ...

  7. 力扣(LeetCode) 771. 宝石与石头

    给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...

  8. C# 图片人脸识别

    此程序基于 虹软人脸识别进行的开发 前提条件从虹软官网下载获取ArcFace引擎应用开发包,及其对应的激活码(App_id, SDK_key)将获取到的开发包导入到您的应用中 App_id与SDK_k ...

  9. 从flask视角理解angular(三)ORM VS Service

    把获取模型数据的任务重构为一个单独的服务,它将提供英雄数据,并把服务在所有需要英雄数据的组件间共享. @Injectable() export class HeroService { getHeroe ...

  10. Altium Designer PCB的时候 高亮显示引脚连线

    按住Ctrl ,左击连线,就可以高亮显示两个连接的引脚.