쇼핑

8033 단어
E -
Pearls
Time Limit:1000MS    Memory Limit:10000KB    64bit IO Format:%I64d & %I64u
SubmitStatus
Description
In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces a lot of jewelry with pearls in it. The Royal Pearl has its name because it delivers to the royal family of Pearlania. But it also produces bracelets and necklaces for ordinary people. Of course the quality of the pearls for these people is much lower then the quality of pearls for the royal family.In Pearlania pearls are separated into 100 different quality classes. A quality class is identified by the price for one single pearl in that quality class. This price is unique for that quality class and the price is always higher then the price for a pearl in a lower quality class. Every month the stock manager of The Royal Pearl prepares a list with the number of pearls needed in each quality class. The pearls are bought on the local pearl market. Each quality class has its own price per pearl, but for every complete deal in a certain quality class one has to pay an extra amount of money equal to ten pearls in that class. This is to prevent tourists from buying just one pearl. Also The Royal Pearl is suffering from the slow-down of the global economy. Therefore the company needs to be more efficient. The CFO (chief financial officer) has discovered that he can sometimes save money by buying pearls in a higher quality class than is actually needed.No customer will blame The Royal Pearl for putting better pearls in the bracelets, as long as the prices remain the same. For example 5 pearls are needed in the 10 Euro category and 100 pearls are needed in the 20 Euro category. That will normally cost: (5+10)*10+(100+10)*20 = 2350 Euro.Buying all 105 pearls in the 20 Euro category only costs: (5+100+10)*20 = 2300 Euro. The problem is that it requires a lot of computing work before the CFO knows how many pearls can best be bought in a higher quality class. You are asked to help The Royal Pearl with a computer program. Given a list with the number of pearls and the price per pearl in different quality classes, give the lowest possible price needed to buy everything on the list. Pearls can be bought in the requested,or in a higher quality class, but not in a lower one.
Input
The first line of the input contains the number of test cases. Each test case starts with a line containing the number of categories c (1<=c<=100). Then, c lines follow, each with two numbers ai and pi. The first of these numbers is the number of pearls ai needed in a class (1 <= ai <= 1000). The second number is the price per pearl pi in that class (1 <= pi <= 1000). The qualities of the classes (and so the prices) are given in ascending order. All numbers in the input are integers.
Output
For each test case a single line containing a single number: the lowest possible price needed to buy everything on the list.
Sample Input
2
2
100 1
100 2
3
1 10
1 11
100 12

Sample Output
330
1344

 
이 다이아몬드를 사는 데 최소 얼마가 들고, 각 품질의 다이아몬드를 사려면 반드시 10개를 더 사야 하며, 요구하는 것보다 질이 좋은 다이아몬드를 살 수 있다는 뜻이다.
곰곰이 생각해 보면 품질을 요구하는 것보다 높은 다이아몬드를 사는 것이 가장 좋은 상황이라면 품질을 요구하는 것과 품질을 구매하는 것 사이의 다이아몬드는 모두 품질을 구매하는 다이아몬드로 사야 한다는 것을 알 수 있다.예를 들어 품질 2의 다이아몬드를 품질 5로 샀다면 품질 3, 4도 모두 5를 사야 한다.가령 3이 5를 사지 않고 3 또는 4를 산다고 가정하면 3, 4는 10개를 더 구매한 후에 5보다 10개를 더 사지 않는 것보다 더 싸다는 것을 의미한다. 이렇게 싼 이상 품질 2가 3, 4를 사는 것이 5를 사는 것보다 낫다는 것은 모순이다.
dp[i]는 앞의 i개의 물건의 가장 좋은 상황을 나타낸다. (이 i개의 물건은 품질이 작은 것에서 큰 것으로 배열된다면) 그래서 dp는 순환해서 몇 번째 것에서 모두 사면 가장 좋은 상황을 찾을 수 있다.
코드:
#include<stdio.h>
#include<string.h>
int a[110],b[110],c[110],dp[110];
int main()
{
    int T,N;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&N);
        int i,j,min;
        c[0]=0;
        dp[0]=0;
        for(i=1; i<=N; i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            c[i]=c[i-1]+a[i];  //c[i]   i       ,    j i    
        }
        for(i=1; i<=N; i++)
        {
            min=999999999;
            for(j=0; j<i; j++)     //   i  ,j=0     i
                if(min>dp[j]+(c[i]-c[j]+10)*b[i]) min=dp[j]+(c[i]-c[j]+10)*b[i];
            dp[i]=min;
        }
        printf("%d
",dp[N]); } return 0; }

O - Lighting System Design
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit Status
Description
You are given the task to design a lighting system for ahuge conference hall. After doing a lot of calculation & sketching, youhave figured out the requirements for an energy-efficient design that canproperly illuminate the entire hall. According to your design, you need lampsof n different power ratings. For some strange current regulationmethod, all the lamps need to be fed with the same amount of current. So, eachcategory of lamp has a corresponding voltage rating. Now, you know the numberof lamps and cost of every single unit of lamp for each category. But theproblem is that you are to buy equivalent voltage sources for all the lampcategories. You can buy a single voltage source for each category (each sourceis capable of supplying to infinite number of lamps of its voltage rating) andcomplete the design. But the accounts section of your company soon figures outthat they might be able to reduce the total system cost by eliminating some ofthe voltage sources and replacing the lamps of that category with higher ratinglamps. Certainly you can never replace a lamp by a lower rating lamp as someportion of the hall might not be illuminated then. You are more concerned aboutmoney-saving rather than energy-saving. Find the minimum possible cost todesign the system.
Input
Input starts with an integer T (≤ 100),denoting the number of test cases.
Each case starts with a line containing an integer n (1≤ n ≤ 1000). Each of the next n lines contains fourintegers Vi, Ki, Ci and Li (1≤ Vi ≤ 105, 1 ≤ Ki ≤1000, 1 ≤ Ci ≤ 10, 1 ≤ Li ≤ 100).Here the integers in ith line havethe following meaning.
1.      Vi meansthe voltage rating,
2.      Ki meansthe cost of a voltage source of this category,
3.      Ci meansthe cost of a lamp of this category and
4.      Li meansthe number of required lamps of this category.
You can assume that thevoltage rating for the categories will be distinct.
Output
For each case, print the case number and the minimumpossible cost to design the system.
Sample Input
1
3
100 500 10 20
120 600 8 16
220 400 7 18
Sample Output
Case 1: 778
이전 문제와 마찬가지로, 단지 먼저 등불의 출력에 대해 순서를 정해야 한다.
코드:
#include<stdio.h>
#include<string.h>
int a[1010][4],c[1010],dp[1010];
int cmp(const void *a,const void *b)
{
    return *(int*)a-*(int*)b;
}
int main()
{
    int T,P=0;
    scanf("%d",&T);
    for(P=1; P<=T; P++)
    {
        int N;
        scanf("%d",&N);
        int i,j;
        for(i=1; i<=N; i++) scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i][2],&a[i][3]);
        qsort(a[1],N,sizeof(a[0]),cmp);
        c[0]=0;
        dp[0]=0;
        for(i=1; i<=N; i++) c[i]=c[i-1]+a[i][3];
        for(i=1; i<=N; i++)
        {
            int min=999999999;
            for(j=0; j<i; j++)
            {
                if(min>dp[j]+(c[i]-c[j])*a[i][2]+a[i][1]) min=dp[j]+(c[i]-c[j])*a[i][2]+a[i][1];
                dp[i]=min;
            }
        }
        printf("Case %d: %d
",P,dp[N]); } return 0; }

이런 물건을 사는 문제는 아마도 네가 그보다 질이 좋은 물건을 살 수 있을 것이다. 모든 물건을 살 때 일정한 돈을 더 내고 최소한의 비용을 요구해야 한다.사실 품질을 작은 것부터 큰 것까지 순서를 정한 다음에 이 방법에 따라 dp순환을 하면 됩니다. 모든 물건이 얼마인지 상관하지 않아도 됩니다.

좋은 웹페이지 즐겨찾기