sicily 1099. Packing Passengers

原创 2015年11月17日 16:20:48

1099. Packing Passengers

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

PTA, Pack ‘em Tight Airlines is attempting the seemingly impossible—to fly with only full planes and still make a profit. Their strategy is simplicity and efficiency. Their fleet consists of 2 types of equipment (airline lingo for airplanes). Type A aircraft cost costA dollars to operate per flight and can carry passengersA passengers. Type B aircraft cost costB dollars to operate per flight and can carry passengersB passengers.

PTA has been using software that works well for fewer than 100 passengers, but will be far too slow for the number of passengers they expect to have with larger aircraft. PTA wants you to write a program that fills each aircraft to capacity (in keeping with the name Pack 'em Tight) and also minimizes the total cost of operations for that route.

Input

The input file may contain data sets. Each data set begins with a line containing the integer n (1 <= n <= 2,000,000,000) which represents the number of passengers for that route. The second line contains costA and passengersA, and the third line contains costB and passengersB. There will be white space between the pairs of values on each line. Here, costA, passengersA, costB, and passengersB are all nonnegative integers having values less than 2,000,000,001.
After the end of the final data set, there is a line containing “0” (one zero) which should not be processed.

Output

For each data set in the input file, the output file should contain a single line formatted as follows:
Data set <N>: <A> aircraft A, <B> aircraft B
Where <N> is an integer number equal to 1 for the first data set, and incremented by one for each subsequent data set, <A> is the number of airplanes of type A in the optimal solution for the test case, and <B> is the number of airplanes of type B in the optimal solution. The 'optimal' solution is a solution that lets PTA carry the number of passengers specified in the input for that data set using only airplanes loaded to their full capacity and that minimizes the cost of operating the required flights. If multiple alternatives exist fitting this description, select the one that uses most airplanes of type A. If no solution exists for PTA to fly the given number of passengers, the out line should be formatted as follows:
Data set <N>: cannot be flown

Sample Input

600
30 20
20 40
550
1 13
2 29
549
1 13
2 29
2000000000
1 2
3 7
599
11 20
22 40
0

Sample Output

Data set 1: 0 aircraft A, 15 aircraft B
Data set 2: 20 aircraft A, 10 aircraft B
Data set 3: 11 aircraft A, 14 aircraft B
Data set 4: 6 aircraft A, 285714284 aircraft B
Data set 5: cannot be flown

题目分析

两架飞机装人,要求油费最少
飞机一定要装满人
飞机还可能不能装人,就为了弄个除0的坑


#include <stdio.h>

int main() {
  long long total;
  int count = 1;
  while (scanf("%lld", &total)) {
    if (total == 0)
      break;

    long long ca, pa, cb, pb;
    scanf("%lld%lld%lld%lld", &ca, &pa, &cb, &pb);
    bool judge = false;

    if (pa == 0) {
      if (pb == 0) {
        printf("Data set %d: cannot be flown\n", count++);
      } else {
        if (total % pb != 0) {
          printf("Data set %d: cannot be flown\n", count++);
        } else {
          printf("Data set %d: 0 aircraft A, %lld aircraft B\n",
             count++, total / pb);
        }
      }
      continue;
    }
    if (pb == 0) {
      if (pa == 0) {
        printf("Data set %d: cannot be flown\n", count++);
      } else {
        if (total % pa != 0) {
          printf("Data set %d: cannot be flown\n", count++);
        } else {
          printf("Data set %d: %lld aircraft A, 0 aircraft B\n",
             count++, total / pa);
        }
      }
      continue;
    }

    if (ca * pb > cb * pa) {
      judge = true;
      long long temp;
      temp = pa; pa = pb; pb = temp;
      temp = ca; ca = cb; cb = temp;
    }

    long long numa = total / pa;
    long long numb = 0;
    total = total % pa;
    while (total % pb != 0 && numa > 0) {
      if (numa > 0) {
        numa--;
        total += pa;
      } else {
        break;
      }
    }
    if (total % pb != 0) {
      printf("Data set %d: cannot be flown\n", count++);
    } else {
      numb = total / pb;
      if (judge) {
        numa += numb;
        numb = numa - numb;
        numa = numa - numb;
      }
      printf("Data set %d: %lld aircraft A, %lld aircraft B\n",
             count++, numa, numb);
    }
  }
  return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

中山大学Sicily在线测评系统题目分类

Classified Problems on Online Judge 练习题选自以下在线测评系统 * sicily: http://soj.me, 中山大学Sicily在线测评系统 ...
  • cuhkljt
  • cuhkljt
  • 2013年06月26日 21:39
  • 4795

1099端口占用问题解决方案

最近在开发的时候,IDEA工具意外退出了,再次启动之后,启动web工程报1099端口已经被占用了,现在将解决方法总结如下: 1.在windows命令行窗口下执行: C:\>netstat -aon|...
  • qq991029781
  • qq991029781
  • 2016年05月25日 11:32
  • 6236

【git】创建一个新的本地仓库并上传代码

root@Ubuntu32:/home/zhangbin/alex/gitProject# ls gitweb-theme   meTestLocalBufferQueue.git 新建一个文件夹 r...
  • commshare
  • commshare
  • 2014年03月05日 09:31
  • 4769

Sicily 1099. Packing Passengers【最大公约数】

题目链接在此 遍历肯定超时!!! 转自这位大神 1.设 (1)pA:每架A飞机能载的人数,cA:每架A飞机的开销,nA:A飞机的数量 (2)pB:每架B飞机能载的人数,cB:每架B飞机的开销,...
  • CharlieLincy
  • CharlieLincy
  • 2014年12月08日 11:57
  • 389

Sicily 1099. Packing Passengers

已知乘客总数n,A类飞机的运输费用cA、客容量pA,B类飞机的运输费用cB、客容量pB,设A类飞机有A架,B类飞机有B架,问是否存在pA*A+pB*B=n;若存在,还要满足cA*A+cB*B最小;若存...
  • Ederick
  • Ederick
  • 2012年02月19日 23:53
  • 764

【论文笔记】T-Finder-A Recommender System for Finder Passengers and vacant Taxis

文章研究了一个系统,针对于两个不同的人群,分别是出租车司机和乘客,对于出租车司机而言,为他们提供最好的停靠点或是最容易在巡航中等到乘客的路段,对于乘客而言,为他们提供最好的停靠点或路段,以便能够更方便...
  • gougoua01
  • gougoua01
  • 2015年12月03日 19:32
  • 381

【模拟】NCPC 2014 K Train passengers

题目链接:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797 题目大意:   有N个车站,火车一共可以坐M个人,每个车站下车Ai,...
  • u010568270
  • u010568270
  • 2016年08月31日 19:37
  • 211

nike air max pas cher also had to apologize this contact with the passengers. But he admitted that t

also had to apologize this contact with the passengers. But he admitted that the conductor why do no...
  • u020370259
  • u020370259
  • 2014年09月03日 19:11
  • 16

CSU1584: Train Passengers

Description Input Output Sample Input 1 2 0 1 1 1 0 0 ...
  • libin56842
  • libin56842
  • 2015年04月26日 17:46
  • 702

Bin Packing-算是一个复杂度优化的好思想

Bin Packing My Tags   (Edit)   Source : SWERC 2005   Time limi...
  • cyb6100300115
  • cyb6100300115
  • 2012年07月08日 13:55
  • 3011
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:sicily 1099. Packing Passengers
举报原因:
原因补充:

(最多只允许输入30个字)