Codeforces Round #367 (Div. 2) A , B , C
1 second
256 megabytes
standard input
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.
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个出租车的位置和速度(xi,yi,vi),求某个出租车到你的最短时间;
思路:直接暴力就是;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 1e-10
const int N=3e5+,M=1e6+,mod=1e9+,inf=1e9+;
double jilu(double a,double b,double c,double d)
{
return sqrt((d-b)*(d-b)+(c-a)*(c-a));
}
int main()
{
int x,y,z,i,t;
double a,b;
scanf("%lf%lf",&a,&b);
scanf("%d",&x);
double ans=1000000000.0;
while(x--)
{
double xi,yi,vi;
scanf("%lf%lf%lf",&xi,&yi,&vi);
ans=min(ans,jilu(xi,yi,a,b)/vi);
}
printf("%f\n",ans);
return ;
}
2 seconds
256 megabytes
standard input
standard output
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.
题意:给你一个数组,q个询问,求小于等于mi的数的个数;
思路:二分查找;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 1e-10
const int N=3e5+,M=1e6+,mod=1e9+,inf=1e9+;
int a[N];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
for(i=;i<x;i++)
scanf("%d",&a[i]);
sort(a,a+x);
scanf("%d",&y);
while(y--)
{
scanf("%d",&z);
int pos=upper_bound(a,a+x,z)-a;
printf("%d\n",pos);
}
return ;
}
1 second
256 megabytes
standard input
standard output
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个字符串,第i个字符串要翻转需要花费a[i],使得最后的字符串成字典序排列,求最小花费,始终不行输出-1;
思路:dp,dp[i][0]表示第i个字符串不翻转成字典序排列的花费,dp[i][1]表示第i个字符串翻转成字典序排列的花费;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=2e6+,inf=1e9+;
const ll INF=1e17;
ll dp[N][];
string str1[N];
string str2[N];
ll a[N];
void init()
{
for(int i=;i<N;i++)
dp[i][]=dp[i][]=INF;
}
int main()
{
int x,y,z,i,t;
init();
scanf("%d",&x);
for(i=;i<=x;i++)
scanf("%I64d",&a[i]);
for(i=;i<=x;i++)
{
cin>>str1[i];
str2[i]=str1[i];
reverse(str2[i].begin(),str2[i].end());
}
dp[][]=;
dp[][]=a[];
for(i=;i<=x;i++)
{
if(str1[i]>=str1[i-])
dp[i][]=min(dp[i][],dp[i-][]);
if(str1[i]>=str2[i-])
dp[i][]=min(dp[i][],dp[i-][]);
if(str2[i]>=str1[i-])
dp[i][]=min(dp[i][],dp[i-][]+a[i]);
if(str2[i]>=str2[i-])
dp[i][]=min(dp[i][],dp[i-][]+a[i]);
}
ll ans=min(dp[x][],dp[x][]);
if(ans<INF)
printf("%I64d\n",ans);
else
printf("-1\n");
return ;
}
Codeforces Round #367 (Div. 2) A , B , C的更多相关文章
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset
题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 ...
- Codeforces Round #367 (Div. 2) C. Hard problem
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...
- Codeforces Round #367 (Div. 2) (A,B,C,D,E)
Codeforces Round 367 Div. 2 点击打开链接 A. Beru-taxi (1s, 256MB) 题目大意:在平面上 \(n\) 个点 \((x_i,y_i)\) 上有出租车,每 ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(01字典树求最大异或值)
http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset Trie
题目链接: http://codeforces.com/contest/706/problem/D D. Vasiliy's Multiset time limit per test:4 second ...
- Codeforces Round #367 (Div. 2)
A题 Beru-taxi 随便搞搞.. #include <cstdio> #include <cmath> using namespace std; int a,b,n; s ...
随机推荐
- Cocos2d-x Lua中帧动画
帧动画就是按一定时间间隔.一定的顺序.一帧一帧地显示帧图片.我们的美工要为精灵的运动绘制每一帧图片,因此帧动画会由很多帧组成,按照一定的顺序切换这些图片就可以了. 在Cocos2d-x Lua中播放帧 ...
- jQuery实现鼠标放到图片上,放大图片
<script src="../../Script/jquery-1.7.2.js" type="text/javascript"></scr ...
- hdu 4617 Weapon【异面直线距离——基础三维几何】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4617 Weapon Time Limit: 3000/1000 MS (Java/Others) ...
- Markov chain
w https://en.wikipedia.org/wiki/Markov_chain https://zh.wikipedia.org/wiki/马尔科夫链 In probability theo ...
- python系列四:Python3字符串
#!/usr/bin/python #Python3 字符串#可以截取字符串的一部分并与其他字段拼接var1 = 'Hello World!'print ("已更新字符串 : ", ...
- ASP-DateAdd时间增加
ASP内置函数DateAdd(interval, number, date) 1.interval标识你要加的日期部分,具体参数如下:yyyy → 年m → 月d → 日h → 小时n → 分钟s → ...
- GDI+绘制图形和画刷填充图形
GDI+可以再Windows窗体应用程序中以编程方式绘制图形等. 可以在VS里新建项目-Windows窗体应用程序-建一个窗体.首先引入命名空间using System.Drawing.Imaging ...
- Delphi重定义的消息结构
// 除去DDE和MDI消息,一共159个消息,其中部分消息仅仅的转定义 // 普通消息,有两个参数和结果 PMessage = ^TMessage; TMessage = packed record ...
- Python 网络编程——socket
一 客户端/服务器架构 客户端(Client)服务器(Server)架构,即C/S架构,包括 1.硬件C/S架构(打印机) 2.软件C/S架构(web服务) 理想/目标状态—— 最常用的软件服务器是 ...
- Linux下源码安装redis,编译安装
1.下载redis源码 [root@localhost opt]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz 2.解压缩 [ ...