Codeforces Round #367 (Div. 2) 水A B

 
Codeforces Round #367 (Div. 2)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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 xiyi and vi ( - 100 ≤ xi, yi ≤ 1001 ≤ 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.

Output

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 .

Examples
input
0 0
2
2 0 1
0 2 2
output
1.00000000000000000000
input
1 3
3
3 3 2
-2 3 6
-2 7 10
output
0.50000000000000000000
Note

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.

题意:给出定点坐标,n个车的位置和速度,求任一车到点的最短时间。(水题)

<span style="font-size:18px;">#include<cstdio>
#include<cmath>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;

int main(){
	int n,i;
	double a,b,x[1010],y[1010],v[1010];
	scanf ("%lf %lf",&a,&b);
	scanf ("%d",&n);
	double mint=INF;
	double s,t;
	for (i=0;i<n;i++){
		scanf ("%lf %lf %lf",&x[i],&y[i],&v[i]);
		s=sqrt((x[i]-a)*(x[i]-a)+((y[i]-b)*(y[i]-b)));
		t=s/v[i];
		mint=min(mint,t);
	}
	printf ("%lf\n",mint);
	return 0;
} //应该能过,没交。</span>

B. Interesting drink

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".

Input

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.

Output

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.

Example
input
5
3 10 8 6 11
4
1
10
3
11
output
0
4
1
5
Note

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 123 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.

题意:给出每个商店饮料的价钱,问每天m[i]元可以去几家店买饮料

二分:

<span style="font-size:18px;">#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int n,q,i,s;
	int x[100100],m[100100];
	scanf ("%d",&n);
	for (i=0;i<n;i++){
		scanf ("%d",&x[i]);
	}
	sort(x,x+n);
	scanf ("%d",&q);
	for (i=0;i<q;i++){
		scanf ("%d",&m[i]);
		s=upper_bound(x,x+n,m[i])-x;
		printf ("%d\n",s);
	}
	
	return 0;
}</span>
树状数组:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int C[100100];
int nn;
int lowbit(int x){
	return x&(-x);
}
void update(int x,int y){
	while (x<=nn){
		C[x]+=y;
		x+=lowbit(x);
	}
	
}
int sum(int x){
	int sum=0;
	while (x>0){
		sum+=C[x];
		x-=lowbit(x);
	}
	return sum;
	
}
int main(){
	int t,n,q,i;
	int m,x;
	nn=100100;
		scanf ("%d",&n);
		while (n--){
			scanf ("%d",&x);
			update(x,1);
		}
		scanf ("%d",&q);
		while (q--){
			scanf ("%d",&m);
			if (m>nn)
			m=nn-1;
			printf ("%d\n",sum(m));	
		}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值