关于一些初级ACM竞赛题目的分析和题解(七)

                    

关于一些初级ACM竞赛题目的分析和题解(七)

            昨晚和cy1999相约一起打cf,结果晚了一个小时哭进的时候菜都快凉了,幸亏都skip了不然就掉分到newbie了,下面上题:
A. Supermarket
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that a yuan for bkilos (You don't need to care about what "yuan" is), the same as a / b yuan for a kilo.

Now imagine you'd like to buy m kilos of apples. You've asked n supermarkets and got the prices. Find the minimum cost for those apples.

You can assume that there are enough apples in all supermarkets.

Input

The first line contains two positive integers n and m (1 ≤ n ≤ 5 0001 ≤ m ≤ 100), denoting that there are n supermarkets and you want to buy m kilos of apples.

The following n lines describe the information of the supermarkets. Each line contains two positive integers a, b (1 ≤ a, b ≤ 100), denoting that in this supermarket, you are supposed to pay a yuan for b kilos of apples.

Output

The only line, denoting the minimum cost for m kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed 10 - 6.

Formally, let your answer be x, and the jury's answer be y. Your answer is considered correct if .

Examples
input
3 5
1 2
3 4
1 3
output
1.66666667
input
2 1
99 100
98 99
output
0.98989899
Note

In the first sample, you are supposed to buy 5 kilos of apples in supermarket 3. The cost is 5 / 3 yuan.

In the second sample, you are supposed to buy 1 kilo of apples in supermarket 2. The cost is 98 / 99yuan.


这道题是输入n,m(n小于5000,m小于100),n表示n家超市,m表示要买m斤,以下n行输入a,b两个数(a,b均小于100) 表示a元b斤  a/b表示单个成本,输出买m斤的最小花费,下面是代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    double c,a,b,d,m;  //  定义含浮点的变量
    cin>>n>>m;  //  输入n,m
    d=1000;  //  先整一个比较大的数
    while(n--)
        {cin>>a>>b;
        c=a/b;
        if(c<=d)d=c;
        }
        printf("%.8lf",d*m);  //  输出小数点后八位的结果

}
若有小数出现,就在定义变量时用double,而输出时根据小数的位数若要8位就printf("%.8lf",a);   %.nlf表示n位小数,


A. Chat room
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.

Input

The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.

Output

If Vasya managed to say hello, print "YES", otherwise print "NO".

Examples
input
ahhellllloou
output
YES
input
hlelo
output
NO
这一题是输入一行字符串,若存在顺序hello,则就输出YES,否则输出NO;下面是代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int j,l,c;
    char a[1000],b[5];  // 定义字符串
    b[0]='h';  //  字符串赋值
    b[1]='e';
    b[2]='l';
    b[3]='l';
    b[4]='o';
    gets (a);  //  输入字符串
    j=0;
    l=strlen(a);  //  找到字符串长度
    for (int i=0;i<=l-1;i++)
        {if (a[i]==b[j])
            j++;  //  计数

            if(j==5)
                return 0*printf("YES");
                }
    if(j!=5) printf("NO");  //输出

}
注意定义字符串时,如b[5]表示可容纳五个字符,即读不到b[5],辣鸡monster_ayb定义的是b[4]结果老是出错,多亏cy1999巨巨指出才发现,感谢cy1999害羞










猜你喜欢

转载自blog.csdn.net/monster_ayb/article/details/79224154