8月1号水题走一波

Posted wkfvawl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8月1号水题走一波相关的知识,希望对你有一定的参考价值。

A. Generate Login

The preferred way to generate user login in Polygon is to concatenate a prefix of the user‘s first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.

You are given the first and the last name of a user. Return the alphabetically(字母顺序地) earliest login they can get (regardless of other potential Polygon users).

As a reminder, a prefix(前缀) of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and ‘bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".

Input

The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.

Output

Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.

Examples
input
harry potter
output
hap
input
tom riddle
output
tomr
 

 

题目意思:给你用户的名和姓,让你生成一个按字母顺序的最短登录名,原则是:名(也就是a串)和姓(也就是b串)都要保留第一个字母,a串除了第一的字母之后的要取到字典序不大于b串第一个字母位置。

说起来还是很繁琐,其实这个有点生活气息,我们平时上网也有这样处理用户名字的,当时我是第二个出这道题的,多少是有点猜的,不过猜对了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 char a[100],b[100];
 6 char c[100];
 7 int main()
 8 {
 9     int i,lena,lenb,counts;
10     scanf("%s",&a);
11     scanf("%s",&b);
12     counts=1;
13     lena=strlen(a);
14     lenb=strlen(b);
15     for(i=1;i<lena;i++)
16     {
17         if(a[i]<b[0])
18         {
19             counts++;
20         }
21         else
22         {
23             break;
24         }
25     }
26     for(i=0;i<counts;i++)
27     {
28         c[i]=a[i];
29     }
30     c[i]=b[0];
31     i++;
32     c[i]=
;
33     printf("%s",c);
34     return 0;
35 }

 

 

Boxes Packing

Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.

Mishka can put a box i into another box j if the following conditions are met:

  • i-th box is not put into another box;
  • j-th box doesn‘t contain any other boxes;
  • box i is smaller than box j (ai < aj).

Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.

Help Mishka to determine the minimum possible number of visible boxes!

Input

The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

Output

Print the minimum possible number of visible boxes.

Examples
Input
3
1 2 3
Output
1
Input
Copy
4
4 2 4 3
Output
2
Note

In the first example it is possible to put box 1 into box 2, and 2 into 3.

In the second example Mishka can put box 2 into box 3, and box 4 into box 1.

 

题目意思:套盒子,尺寸大的盒子能装下尺寸小的盒子,给你一些盒子,问你最后最少能剩下多少的盒子。

解题思路:这个题有点俄罗斯套娃的意思,大的能装下小的,那么我们只需要看看最后剩下尺寸最大的盒子的个数就行了。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int a[5010];
 6 int main()
 7 {
 8     int n,counts,maxs,i;
 9     scanf("%d",&n);
10     for(i=0; i<n; i++)
11     {
12         scanf("%d",&a[i]);
13     }
14     sort(a,a+n);
15     counts=1;
16     maxs=1;
17     for(i=1; i<n; i++)
18     {
19         if(a[i]==a[i-1])
20         {
21             counts++;
22             if(maxs<counts)
23             {
24                 maxs=counts;
25             }
26         }
27         else
28         {
29             counts=1;
30         }
31     }
32     printf("%d
",maxs);
33     return 0;
34 }

 

这里再给出使用map这一容器的做法:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<map>
 5 using namespace std;
 6 int main()
 7 {
 8     int n,maxs,i,num;
 9     maxs=-1;
10     map<int,int>mp;
11     scanf("%d",&n);
12     for(i=0; i<n; i++)
13     {
14         scanf("%d",&num);
15         mp[num]++;
16         maxs=max(maxs,mp[num]);
17     }
18     printf("%d
",maxs);
19     return 0;
20 }

 

 

 

以上是关于8月1号水题走一波的主要内容,如果未能解决你的问题,请参考以下文章

水题水一波

一波水题 MZOJ 1035: 贝克汉姆

化悲痛为力量——暑假刷题走起

牛客小白月赛2 总结

每天一道算法题走迷宫

湖北宜昌市发展大道13号水悦城一层120单元是湖北哪个区的