ACM Rank Table



Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status Practice POJ 2393

Description

The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the company C_i (1 <= C_i <= 5,000) cents to produce one unit of yogurt in week i. Yucky's factory, being well-designed, can produce arbitrarily many units of yogurt each week.

Yucky Yogurt owns a warehouse that can store unused yogurt at a constant fee of S (1 <= S <= 100) cents per unit of yogurt per week. Fortuitously, yogurt does not spoil. Yucky Yogurt's warehouse is enormous, so it can hold arbitrarily many units of yogurt.

Yucky wants to find a way to make weekly deliveries of Y_i (0 <= Y_i <= 10,000) units of yogurt to its clientele (Y_i is the delivery quantity in week i). Help Yucky minimize its costs over the entire N-week period. Yogurt produced in week i, as well as any yogurt already in storage, can be used to meet Yucky's demand for that week.

Input

* Line 1: Two space-separated integers, N and S.

* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.

Output

* Line 1: Line 1 contains a single integer: the minimum total cost to satisfy the yogurt schedule. Note that the total might be too large for a 32-bit integer.

Sample Input

4 5
88 200
89 400
97 300
91 500

Sample Output

126900

Hint

OUTPUT DETAILS:
In week 1, produce 200 units of yogurt and deliver all of it. In week 2, produce 700 units: deliver 400 units while storing 300 units. In week 3, deliver the 300 units that were stored. In week 4, produce and deliver 500 units.
        
题目大意:给定周数N,然后给定每周存储每个单元的酸奶需要花费的金额S,然后接下来N行
每行给出第i周制造此酸奶的价格,和顾客的需求量,你要在满足所有顾客需求的情况下,找到一个
最小的成本,且输出该成本(%I64d)
贪心思路:
    一开始想着排序,然后交换了3 4行发现 答案都不一样了,明白这道题不能使用排序,
假设保存第y周的酸奶
因为保存酸奶每周成本是S,如果保存x周的话,那么相应的第y周的酸奶成本就变成了y.price + x * S;
然后因为不能改变周序,所以不排序直接检索,用一个ed来表示 当前能达到的最小价格,(之前的价格+保存成本 和和现在的 价格比较)
具体代码如下:
//
// Create by Running Photon on 2015-03-03
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
const int inf=0x3f3f3f3f;
const int maxn=1e4+5;
const int MOD=5e5+5;

int n, step;
struct fee
{
    int num;
    int price;
}a[maxn];

int main()
{
#ifdef LOCAL
 freopen("in.txt","r",stdin);
 //freopen("out.txt","w",stdout);
#endif
 ios_base::sync_with_stdio(0);

 while(scanf("%d%d", &n, &step)!=EOF){
        ll ans = 0;
        for(int i = 1; i <= n; i++)
            scanf("%d%d", &a[i].price, &a[i].num);
        int ed = a[1].price; ans += ed * a[1].num;
        for(int i = 2; i <= n; i++){
            ed = min(ed + step, a[i].price);//ed自动更新为 当前能达到的最低成本
            ans += a[i].num * ed;
        }
        printf("%I64d\n",ans);
 }
 return 0;
}

E - Sales Report

Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Submit Status Practice POJ 1017

Description

A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.

Input

The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packets of individual size from the smallest size 1*1 to the biggest size 6*6. The end of the input file is indicated by the line containing six zeros.

Output

The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There is no line in the output file corresponding to the last ``null'' line of the input file.

Sample Input

0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0 

Sample Output

2
1  

题目大意就是 输入 1*1 2*2 3*3 4*4 5*5 6*6规格的物品的数量,然后箱子的大小为6*6 你的任务就是,用尽量小的箱子把这些物品装完。
全if else写
贪心过程见代码:
 //
// Create by Running Photon on 2015-03-04
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
const int inf=0x3f3f3f3f;
const int maxn=1e5+5;
const int MOD=5e5+5;
// 贪心思路就是 凑,从大往小凑够就出发,类似拼车
// if else 写了一串 累死了。
int main()
{
#ifdef LOCAL
 freopen("in.txt","r",stdin);
 //freopen("out.txt","w",stdout);
#endif
 ios_base::sync_with_stdio(0);

 int a1, a2, a3, a4, a5, a6;
 while(scanf("%d%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5, &a6)!=EOF && (a1 + a2 + a3 + a4 + a5 + a6)){
        int ans = a4 + a5 + a6 + (a3 + 3) / 4;
        a3 %= 4;
        a1 = a1 - a5 * 11;
        a2 = a2 - a4 * 5;
        if(a3 == 3){
            a2--;
            a1 -= 5;
        }
        else if(a3 == 2){
            a2 -= 3;
            a1 -= 6;
        }
        else if(a3 == 1){
            a2 -= 5;
            a1 -= 7;
        }
        if(a2 < 0){
            a1 += (a2 * 4);
            a2 = 0;
        }
        if(a2 > 0){
            ans += ((a2 + 8) / 9);
            a2 %= 9;
            a1 = a1 - 36 + a2 * 4;
        }
        if(a1 > 0)
            ans += ((a1 + 35) / 36);
        printf("%d\n",ans);
 }

 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值