1092 To Buy or Not to Buy (20 分)

版权声明:转载留名即可 ^_^ https://blog.csdn.net/qq_33375598/article/details/88062150

 

Eva would like to make a string of beads(小球) with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence Eva must check whether a string in the shop contains all the beads she needs. She now comes to you for help: if the answer is Yes, please tell her the number of extra beads she has to buy; or if the answer is No, please tell her the number of beads missing from the string.

For the sake(目的) of simplicity, let's use the characters in the ranges [0-9], [a-z], and [A-Z] to represent the colors. For example, the 3rd string in Figure 1 is the one that Eva would like to make. Then the 1st string is okay since it contains all the necessary beads with 8 extra ones; yet the 2nd one is not since there is no black bead and one less red bead.

Input Specification:

Each input file contains one test case. Each case gives in two lines the strings of no more than 1000 beads which belong to the shop owner and Eva, respectively.

Output Specification:

For each test case, print your answer in one line. If the answer is Yes, then also output the number of extra beads Eva has to buy; or if the answer is No, then also output the number of beads missing from the string. There must be exactly 1 space between the answer and the number.

Sample Input 1:

ppRYYGrrYBR2258
YrR8RrY

Sample Output 1:

Yes 8

Sample Input 2:

ppRYYGrrYB225
YrR8RrY

Sample Output 2:

No 2

 

参考代码:

//甲 到底买不买
#include<cstdio>
#include<cstring>

const int maxn = 1010;
char whole[maxn], target[maxn];
int hashTable[80];
int miss = 0;//缺少的珠子

int changeInt(char c){
  if(c >= '0' && c <= '9') return c - '0';
  if(c >= 'A' && c <= 'Z') return c - 'A' + 10;
  if(c >= 'a' && c <= 'z') return c - 'a' + 36;
}

 int main(int argc, char const *argv[])
 {
  memset(hashTable, 0, sizeof(hashTable));
   fgets(whole, maxn + 1, stdin);
   fgets(target, maxn + 1, stdin);
   int len1 = strlen(whole) - 1;
   int len2 = strlen(target) - 1;

for (int i = 0; i < len1; ++i)
{
  int id = changeInt(whole[i]);
  hashTable[id]++;
}

for (int i = 0; i < len2; ++i)
{
  int id = changeInt(target[i]);
  hashTable[id]--;
  if(hashTable[id] < 0) miss++;
}

if(miss > 0) printf("No %d\n", miss);
else printf("Yes %d\n", len1 - len2);
   return 0;
 }



 

BUY LOW, BUY LOWER

08-09

DescriptionnnThe advice to "buy low" is half the formula to success in the bovine stock market.To be considered a great investor you must also follow this problems' advice: n "Buy low; buy lower"nnEach time you buy a stock, you must purchase it at a lower price than the previous time you bought it. The more times you buy at a lower price than before, the better! Your goal is to see how many times you can continue purchasing at ever lower prices. nnYou will be given the daily selling prices of a stock (positive 16-bit integers) over a period of time. You can choose to buy stock on any of the days. Each time you choose to buy, the price must be strictly lower than the previous time you bought stock. Write a program which identifies which days you should buy stock in order to maximize the number of times you buy. nnHere is a list of stock prices: n Day 1 2 3 4 5 6 7 8 9 10 11 12nnPrice 68 69 54 64 68 64 70 67 78 62 98 87nnnThe best investor (by this problem, anyway) can buy at most four times if each purchase is lower then the previous purchase. One four day sequence (there might be others) of acceptable buys is: nDay 2 5 6 10nnPrice 69 68 64 62nInputnn* Line 1: N (1 <= N <= 5000), the number of days for which stock prices are given nn* Lines 2..etc: A series of N space-separated integers, ten per line except the final line which might have fewer integers. nOutputnnTwo integers on a single line: n* The length of the longest sequence of decreasing prices n* The number of sequences that have this length (guaranteed to fit in 31 bits) nnIn counting the number of solutions, two potential solutions are considered the same (and would only count as one solution) if they repeat the same string of decreasing prices, that is, if they "look the same" when the successive prices are compared. Thus, two different sequence of "buy" days could produce the same string of decreasing prices and be counted as only a single solution. nSample Inputnn12n68 69 54 64 68 64 70 67 78 62n98 87nSample Outputnn4 2 问答

Buy the souvenirs Buy the souvenirs

09-23

Problem DescriptionrnWhen the winter holiday comes, a lot of people will have a trip. Generally, there are a lot of souvenirs to sell, and sometimes the travelers will buy some ones with pleasure. Not only can they give the souvenirs to their friends and families as gifts, but also can the souvenirs leave them good recollections. All in all, the prices of souvenirs are not very dear, and the souvenirs are also very lovable and interesting. But the money the people have is under the control. They can’t buy a lot, but only a few. So after they admire all the souvenirs, they decide to buy some ones, and they have many combinations to select, but there are no two ones with the same kind in any combination. Now there is a blank written by the names and prices of the souvenirs, as a top coder all around the world, you should calculate how many selections you have, and any selection owns the most kinds of different souvenirs. For instance:rnrnrnrnrnAnd you have only 7 RMB, this time you can select any combination with 3 kinds of souvenirs at most, so the selections of 3 kinds of souvenirs are ABC (6), ABD (7). But if you have 8 RMB, the selections with the most kinds of souvenirs are ABC (6), ABD (7), ACD (8), and if you have 10 RMB, there is only one selection with the most kinds of souvenirs to you: ABCD (10).rn rnrnInputrnFor the first line, there is a T means the number cases, then T cases follow.rnIn each case, in the first line there are two integer n and m, n is the number of the souvenirs and m is the money you have. The second line contains n integers; each integer describes a kind of souvenir. rnAll the numbers and results are in the range of 32-signed integer, and 0<=m<=500, 0 问答

没有更多推荐了,返回首页