杭电Acm1015

(1)大意:

  牛们收购了一个奶酪工厂,接下来的N个星期里,牛奶价格和劳力价格不断起伏.第i周,生产一个单位奶酪需要Ci(1≤Ci≤5000)便士.工厂有一个货栈,保存一单位奶酪,每周需要S(1≤S≤100)便士,这个费用不会变化.货栈十分强大,可以存无限量的奶酪,而且保证它们不变质.工厂接到订单,在第i周需要交付Yi(0≤Yi≤104)单位的奶酪给委托人.第i周刚生产的奶酪,以及之前的存货,都可以作为产品交付.请帮牛们计算这段时间里完成任务的最小代价.

     第1行输入两个整数N和S.接下来N行输入Ci和Yi

(2)解题思路:

  从第二天开始,每天都跟前一天比较,今天的单价是否比昨天的单价+s大,若是,则选择小的。当然,前天的单价+s+s若是比今天的还小,则用前天的+2*s;

(3)感想:真尼玛坑啊,破题一个,英语叙述那么长,怎么看懂?花了一小时才看懂,oj编译环境又那么弱智,真是够了!

(4)代码:

#include<iostream>
using namespace std;
int main()
{
 int Price[100000], Number[100000];
 int week, s, sum = 0;
 cin >> week >> s;
 for (int i = 0;i < week;i++)
 {
  cin >> Price[i];
  cin >> Number[i];
 }
 for (int i = 0;i < week;i++)
 {
  if (i == 0)
  {
   sum = sum + Price[i] * Number[i];
  }
  else
  {
   if (Price[i] >= (Price[i - 1] + s))
   {
    Price[i] = Price[i - 1] + s;
    sum = sum + Price[i]*Number[i];
   }
   else
   {
    sum = sum + Price[i] * Number[i];
   }
  }
 }
 cout << sum << endl;

 return 0;

}


另外附加一种方法,网上看到的:

<code class="hljs cpp has-numbering"><span class="hljs-preprocessor">#include <iostream></span>
<span class="hljs-preprocessor">#include <algorithm></span>

<span class="hljs-keyword">using</span> <span class="hljs-keyword">namespace</span> <span class="hljs-built_in">std</span>;
<span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> maxn = <span class="hljs-number">10000</span> + <span class="hljs-number">5</span>;

<span class="hljs-keyword">int</span> main()
{
    __int64 sum = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">int</span> n, s, c[maxn], y[maxn];
    <span class="hljs-built_in">cin</span> >> n >> s;
    c[<span class="hljs-number">0</span>] = maxn;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">1</span>; i <= n; i++) {
        <span class="hljs-built_in">cin</span> >> c[i] >> y[i];
        c[i] = min (c[i], c[i - <span class="hljs-number">1</span>] + s);
        sum += c[i] * y[i];
    }
    <span class="hljs-built_in">cout</span> << sum << endl;
    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}</code>

你可能感兴趣的:(ACM,杭电)