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 }
  • 相关阅读:
    svn command line tag
    MDbg.exe(.NET Framework 命令行调试程序)
    Microsoft Web Deployment Tool
    sql server CI
    VS 2010 One Click Deployment Issue “Application Validation did not succeed. Unable to continue”
    mshtml
    大厂程序员站错队被架空,只拿着五折工资!苟活和离职,如何选择?
    揭秘!Windows 为什么会蓝屏?微软程序员竟说是这个原因...
    喂!千万别忘了这个C语言知识!(~0 == -1 问题)
    Linux 比 Windows 更好,谁反对?我有13个赞成理由
  • 原文地址:https://www.cnblogs.com/jolin123/p/3446836.html
Copyright © 2011-2022 走看看