zoukankan      html  css  js  c++  java
  • Sicily 1093. Air Express 解题报告

    题目传送门:1093. Air Express

      题目本身没有什么思维上的难度主要考察思维的严密性,注意有可能weight3 * rate3 < weight2 * rate2等情况,调试时注意对每个分支的检查。

    代码:

     1 #include<iostream>
     2 using namespace std;
     3 
     4 int min(int a,int b,int c);
     5 
     6 int main(){
     7     int weight1,weight2,weight3,rate1,rate2,rate3,rate4,weight,set_number = 1;
     8     while(cin >> weight1 >> rate1){
     9         cin >> weight2 >> rate2 >> weight3 >> rate3 >> rate4;
    10         weight1++;
    11         weight2++;
    12         weight3++;
    13         int bound1 = weight1 * rate2,bound2 = weight2 * rate3,bound3 = weight3
    14                 * rate4;
    15         cout << "Set number " << set_number << ":" << endl;
    16         set_number++;
    17         while(cin >> weight && weight != 0){
    18             if(weight < weight1){
    19                 int mini_bound = min(bound1,bound2,bound3);
    20                 if(weight * rate1 <= mini_bound)
    21                     cout << "Weight (" << weight << ") has best price $"
    22                             << weight * rate1 << " (add 0 pounds)" << endl;
    23                 else{
    24                     if(mini_bound == bound1){
    25                         cout << "Weight (" << weight << ") has best price $"
    26                                 << bound1 << " (add " << weight1 - weight
    27                                 << " pounds)" << endl;
    28                     }else if(mini_bound == bound2){
    29                         cout << "Weight (" << weight << ") has best price $"
    30                                 << bound2 << " (add " << weight2 - weight
    31                                 << " pounds)" << endl;
    32                     }else{
    33                         cout << "Weight (" << weight << ") has best price $"
    34                                 << bound3 << " (add " << weight3 - weight
    35                                 << " pounds)" << endl;
    36                     }
    37                 }
    38             }else if(weight < weight2){
    39                 if(bound2 <= bound3){
    40                     if(weight * rate2 <= bound2)
    41                         cout << "Weight (" << weight << ") has best price $"
    42                                 << weight * rate2 << " (add 0 pounds)" << endl;
    43                     else
    44                         cout << "Weight (" << weight << ") has best price $"
    45                                 << bound2 << " (add " << weight2 - weight
    46                                 << " pounds)" << endl;
    47                 }else{
    48                     if(weight * rate2 <= bound3)
    49                         cout << "Weight (" << weight << ") has best price $"
    50                                 << weight * rate2 << " (add 0 pounds)" << endl;
    51                     else
    52                         cout << "Weight (" << weight << ") has best price $"
    53                                 << bound3 << " (add " << weight3 - weight
    54                                 << " pounds)" << endl;
    55                 }
    56             }else if(weight < weight3){
    57                 if(weight * rate3 <= bound3)
    58                     cout << "Weight (" << weight << ") has best price $"
    59                             << weight * rate3 << " (add 0 pounds)" << endl;
    60                 else
    61                     cout << "Weight (" << weight << ") has best price $"
    62                             << bound3 << " (add " << weight3 - weight
    63                             << " pounds)" << endl;
    64 
    65             }else{
    66                 cout << "Weight (" << weight << ") has best price $"
    67                         << weight * rate4 << " (add 0 pounds)" << endl;
    68             }
    69         }
    70         cout << endl;
    71     }
    72     return 0;
    73 }
    74 int min(int a,int b,int c){
    75     return a > b ? (b > c ? c : b) : (a > c ? c : a);
    76 }
  • 相关阅读:
    asp.net(C#)利用QRCode生成二维码(续)-在二维码图片中心加Logo或图像
    C#中DataTable中的Compute方法使用收集
    c#的DateTime.Now函数详解
    附加数据库失败,拒绝访问
    xml文件绑定chenckbox选择框
    Maximum Xor Secondary(单调栈好题)
    Y(类树形DP)
    Average distance(类树形DP)
    Balls and Boxes (模拟题)
    Party at Hali-Bula(树形DP+判断方案数是否唯一)
  • 原文地址:https://www.cnblogs.com/jolin123/p/3446836.html
Copyright © 2011-2022 走看看