连续两场涨分了,虽然还在基础分附近, 但还是很开心~~~~~
Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi.
Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars.
The first line of the input contains two integers a and b ( - 100 ≤ a, b ≤ 100) — coordinates of Vasiliy's home.
The second line contains a single integer n (1 ≤ n ≤ 1000) — the number of available Beru-taxi cars nearby.
The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≤ xi, yi ≤ 100, 1 ≤ vi ≤ 100) — the coordinates of the i-th car and its speed.
It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives.
Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .
0 0 2 2 0 1 0 2 2
1.00000000000000000000
1 3 3 3 3 2 -2 3 6 -2 7 10
0.50000000000000000000
In the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer.
In the second sample, cars 2 and 3 will arrive simultaneously.
题意:
给你你家的坐标(a,b),n个出租车,给出每个车的坐标(x,y)和速度V,求最短时间你可以坐上车。
题解:
签到题,求出距离比上速度即可,注意精度,和 ans的初始值一定要大。
代码:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#define M 100000
using namespace std;
int n,m,t,x,y,a,b,c;
double solo(int a,int b)
{
return sqrt((a-x)*(a-x)+(b-y)*(b-y));
}
int main()
{
scanf("%d%d",&x,&y);
scanf("%d",&n);
double ans=10000;
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&a,&b,&c);
ans=min(ans,solo(a,b)/(double)c);
}
printf("%.6lf\n",ans);
}
B:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins.
Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent mi coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains n integers xi (1 ≤ xi ≤ 100 000) — prices of the bottles of the drink in the i-th shop.
The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink.
Then follow q lines each containing one integer mi (1 ≤ mi ≤ 109) — the number of coins Vasiliy can spent on the i-th day.
Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day.
5 3 10 8 6 11 4 1 10 3 11
0 4 1 5
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop.
题意:
n个物品,给出每个物品单价xi,q天,每天你有m元,问每天你有多少种物品可以选,注意,钱不会攒下。
题解:
给物品单价排个序,用一下upper_bound即可。
代码:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#define M 100010
using namespace std;
int n,m,t,x,y,b;
long long a[M],c[M];
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
}
sort(a,a+n);
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%d",&b);
c[i]=upper_bound(a,a+n,b)-a;
}
for(int i=0;i<m;i++)
{
printf("%I64d\n",c[i]);
}
}
C:
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.
Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the dictionary), but he is not allowed to swap any of them. The only operation he is allowed to do is to reverse any of them (first character becomes last, second becomes one before last and so on).
To reverse the i-th string Vasiliy has to spent ci units of energy. He is interested in the minimum amount of energy he has to spent in order to have strings sorted in lexicographical order.
String A is lexicographically smaller than string B if it is shorter than B (|A| < |B|) and is its prefix, or if none of them is a prefix of the other and at the first position where they differ character in A is smaller than the character in B.
For the purpose of this problem, two equal strings nearby do not break the condition of sequence being sorted lexicographically.
The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of strings.
The second line contains n integers ci (0 ≤ ci ≤ 109), the i-th of them is equal to the amount of energy Vasiliy has to spent in order to reverse the i-th string.
Then follow n lines, each containing a string consisting of lowercase English letters. The total length of these strings doesn't exceed 100 000.
If it is impossible to reverse some of the strings such that they will be located in lexicographical order, print - 1. Otherwise, print the minimum total amount of energy Vasiliy has to spent.
2 1 2 ba ac
1
3 1 3 1 aa ba ac
1
2 5 5 bbb aaa
-1
2 3 3 aaa aa
-1
In the second sample one has to reverse string 2 or string 3. To amount of energy required to reverse the string 3 is smaller.
In the third sample, both strings do not change after reverse and they go in the wrong order, so the answer is - 1.
In the fourth sample, both strings consists of characters 'a' only, but in the sorted order string "aa" should go before string "aaa", thus the answer is - 1.
题意:一共有N个串。你可以对这些串进行反转操作(倒过来),消耗ci的体力值。询问:最少消耗多少体力值能够字典序排序
题解;字符串我不太会,dp我也不太会,而这道题就是dp+字符串处理。 dp[i][j]表示第i个串,j取(0,1)表示翻转或不翻转,所需要的最小代价,状态找到了,四个转移,当前串不反转大于前面串(翻转或不翻转),当前串翻转大于前面串(翻转或不翻转)。
代码:
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
long long dp[MAX][2],n,a[MAX];
string s[MAX],t[MAX];
int main()
{
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++) cin>>s[i],reverse(s[i].begin(),s[i].end()),t[i]=s[i],reverse(s[i].begin(),s[i].end());
for (int i=1;i<=n;i++)
{
dp[i][0]=dp[i][1]=1e16;
if (s[i]>=t[i-1]) dp[i][0]=min(dp[i][0],dp[i-1][1]);
if (s[i]>=s[i-1]) dp[i][0]=min(dp[i][0],dp[i-1][0]);
if (t[i]>=t[i-1]) dp[i][1]=min(dp[i][1],dp[i-1][1]);
if (t[i]>=s[i-1]) dp[i][1]=min(dp[i][1],dp[i-1][0]);
dp[i][1]+=a[i];
}
if (min(dp[n][0],dp[n][1])>5e15) cout<<-1;
else cout<<min(dp[n][0],dp[n][1]);
return 0;
}
D E:会写在补题里。。