usaco 1.2 76 mixing milk 90 Dual Palindromes

Dual Palindromes
Mario Cruz (Colombia) & Hugo Rickeboer (Argentina)

A number that reads the same from right to left as when read from left to right is called a palindrome. The number 12321 is a palindrome; the number 77778 is not. Of course, palindromes have neither leading nor trailing zeroes, so 0220 is not a palindrome.

The number 21 (base 10) is not palindrome in base 10, but the number 21 (base 10) is, in fact, a palindrome in base 2 (10101).

Write a program that reads two numbers (expressed in base 10):

  • N (1 <= N <= 15)
  • S (0 < S < 10000)

and then finds and prints (in base 10) the first N numbers strictly greater than S that are palindromic when written in two or more number bases (2 <= base <= 10).

Solutions to this problem do not require manipulating integers larger than the standard 32 bits.

PROGRAM NAME: dualpal

INPUT FORMAT

A single line with space separated integers N and S.

SAMPLE INPUT (file dualpal.in)

3 25

OUTPUT FORMAT

N lines, each with a base 10 number that is palindromic when expressed in at least two of the bases 2..10. The numbers should be listed in order from smallest to largest.

SAMPLE OUTPUT (file dualpal.out)

26
27
28


Mixing Milk

Since milk packaging is such a low margin business, it is important to keep the price of the raw product (milk) as low as possible. Help Merry Milk Makers get the milk they need in the cheapest possible manner.

The Merry Milk Makers company has several farmers from which they may buy milk, and each one has a (potentially) different price at which they sell to the milk packing plant. Moreover, as a cow can only produce so much milk a day, the farmers only have so much milk to sell per day. Each day, Merry Milk Makers can purchase an integral amount of milk from each farmer, less than or equal to the farmer's limit.

Given the Merry Milk Makers' daily requirement of milk, along with the cost per gallon and amount of available milk for each farmer, calculate the minimum amount of money that it takes to fulfill the Merry Milk Makers' requirements.

Note: The total milk produced per day by the farmers will be sufficient to meet the demands of the Merry Milk Makers.

PROGRAM NAME: milk

INPUT FORMAT

Line 1: Two integers, N and M.
The first value, N, (0 <= N <= 2,000,000) is the amount of milk that Merry Milk Makers wants per day. The second, M, (0 <= M <= 5,000) is the number of farmers that they may buy from.
Lines 2 through M+1: The next M lines each contain two integers, Pi and Ai.
Pi (0 <= Pi <= 1,000) is price in cents that farmer i charges.
Ai (0 <= Ai <= 2,000,000) is the amount of milk that farmer i can sell to Merry Milk Makers per day.

SAMPLE INPUT (file milk.in)

100 5
5 20
9 40
3 10
8 80
6 30

OUTPUT FORMAT

A single line with a single integer that is the minimum price that Merry Milk Makers can get their milk at for one day.

SAMPLE OUTPUT (file milk.out)

630



两道挺有意思的简单题~
一道是进制转化。。。一道是贪心。。。

代码:
View Code
 1 /*
 2 ID: jings_h1
 3 PROG: dualpal
 4 LANG: C++
 5 */
 6 #include<iostream>
 7 #include<fstream>
 8 #include<string.h>
 9 using namespace std;
10 char a[100];
11 bool istrue(char a1[],int times1){
12      for(int k=0;k<times1;k++){
13              if(a1[k]!=a1[times1-k-1])
14                    return false;
15                    }
16      return true;
17 }
18 int main(){
19     ofstream fout ("dualpal.out");
20     ifstream fin ("dualpal.in");
21     int n,m;
22     fin>>n>>m;
23             int times=0;
24          //   char spe='0'-'0';
25             for(int i=m+1;times<n;i++){
26                     memset(a,0,sizeof(a));
27                     int res=0;   
28                     for(int j=2;j<=10;j++){
29                             int temp1=i;
30                             int ssize=0;
31                             while(temp1>0){
32                                  a[ssize++]=temp1%j;
33                                  temp1=temp1/j;
34                                  }
35                             if(istrue(a,ssize)){
36                                     res++;
37                                     }
38                             if(res>=2){
39                                   fout<<i<<endl;
40                                   times++;
41                                   break;
42                                   }
43                                   }
44                                   }
45     return 0;
46 }
47 
48 
49 
50 
51 
52 /*
53 ID: jings_h1
54 PROG: milk
55 LANG: C++
56 */
57 #include<iostream>
58 #include<fstream>
59 #include<algorithm>
60 using namespace std;
61 struct node{
62        int a;
63        int v;
64 };
65 node point[5005];
66 //int a[5000];
67 //int v[5000];
68 bool cmp(const node & b,const node & c){
69      return b.v<c.v;
70 }
71 int main(){
72     ofstream fout ("milk.out");
73     ifstream fin ("milk.in");
74     int n,m;
75     fin>>n>>m;
76             for(int i=0;i<m;i++){
77                     fin>>point[i].v>>point[i].a;
78                     }
79             sort(point,point+m,cmp);
80             int sum=0;
81             for(int j=0;n>0;j++){
82                     if(n>=point[j].a){
83                         sum+=point[j].v*point[j].a;
84                         n-=point[j].a;
85                         }
86                     else{
87                         sum+=point[j].v*n;
88                         break;
89                         }
90                         }
91             fout<<sum<<endl;
92     return 0;
93 }

 

posted on 2012-11-19 17:15  yumao  阅读(208)  评论(0编辑  收藏  举报

导航