zoukankan      html  css  js  c++  java
  • UVa 11369

    题意:

    又到了剁手的季节,购物狂们开始行动,超市也开始行动,规定是:每买三件,可以省去1件最便宜的价格。

    给出买的商品数,和每个商品的价值,求出购物狂一共赚了多少钱,呵呵。

    思路:

    把数据从大到小排序,把3的倍数的商品价值相加,就是答案。

    实现:重写C++STL里的sort()函数的比较函数 bool compare();

    代码:

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 #define MAXN 20000+10
     9 
    10 bool cmp(int a,int b){
    11     if(a>b)return true;
    12     else return false;
    13 }
    14 class Shopaholic{
    15     private:
    16         int thingsNum;
    17         int price[MAXN];
    18         int ansNum;
    19     public:
    20         void init();
    21         void process();
    22 };
    23 void Shopaholic::init(){
    24     memset(price,0,sizeof(price));
    25     ansNum = 0;
    26 }
    27 void Shopaholic::process(){
    28     int cases;
    29     cin>>cases;
    30     while(cases--){
    31         init();
    32         cin>>thingsNum;
    33         for(int i = 0;i < thingsNum;i++){
    34             cin>>price[i];
    35         }
    36         sort(price,price + thingsNum,cmp);
    37         for(int i = 2;i < thingsNum;i += 3){
    38             ansNum += price[i];
    39         }
    40         cout<<ansNum<<endl;
    41 
    42     }
    43 }
    44 
    45 int main()
    46 {
    47     #ifndef ONLINE_JUDGE
    48         freopen("D:\acm.txt","r",stdin);
    49     #endif // ONLINE_JUDGE
    50     Shopaholic shopaholic;
    51     shopaholic.process();
    52     return 0;
    53 }
    Donghua University
  • 相关阅读:
    pytorch的常用接口、操作、注意事项
    pytorch 中conv1d操作
    NLP基本知识点和模型
    深度学习基础理论知识
    对交叉验证的理解
    阅读深度学习论文的一些技巧
    机器学习和深度学习入门总结
    架构思考-业务快速增长时的容量问题
    系统梳理一下锁
    稳定性五件套-限流的原理和实现
  • 原文地址:https://www.cnblogs.com/ohxiaobai/p/4491582.html
Copyright © 2011-2022 走看看