關於一些初級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
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
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 input3 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.
InputThe 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.
OutputIf Vasya managed to say hello, print "YES", otherwise print "NO".
Examples inputahhellllloou
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