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

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.
The first line contains two positive integers n and m (1 ≤ n ≤ 5 000, 1 ≤ 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.
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 .
3 5
1 2
3 4
1 3
1.66666667
2 1
99 100
98 99
0.98989899
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.
#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位小数,
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.
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.
If Vasya managed to say hello, print "YES", otherwise print "NO".
ahhellllloou
YES
hlelo
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