Codeforces Round #367 (Div. 2)

本文解析了三道算法竞赛题目,包括出租车最快到达时间计算、购买饮料的店铺选择以及字符串字典序排列问题,提供了详细的解题思路及代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                                                                                                                    A. Beru-taxi
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 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.

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.


题意:求出所以租车到人该位置最短时间。


<span style="font-size:18px;">#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define eps 1e-7
using namespace std;
const int maxn=1010;
struct node{
   double x,y,t,dis,v;
}nod[maxn];
int main()
{
    double x,y;
    int n;
    while(~scanf("%lf %lf",&x,&y))
    {
        memset(nod,0,sizeof(nod));
        double a,b;
        double sum=100000000;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%lf %lf %lf",&nod[i].x,&nod[i].y,&nod[i].v);
            nod[i].t=sqrt((nod[i].x-x)*(nod[i].x-x)+(nod[i].y-y)*(nod[i].y-y))/nod[i].v;
            //cout << nod[i].t <<endl;
            if(sum-nod[i].t>eps) sum=nod[i].t;
        }
        printf("%f\n",sum);
    }
    return 0;
}
</span>

                                                                                                        

                                                                                                                                  B. Interesting drink
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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".

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


题意:求数组大于给定数x的个数。


解题思路:只要将数组小到大排序,然后二分查找第一个大于x的位置(由于数组从0开始),所以得到的位置就是满足条件数的个数。


<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=100010;
int a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        int q,x;
        scanf("%d",&q);
        for(int i=0;i<q;i++){
            scanf("%d",&x);
            int sum=upper_bound(a,a+n,x) - a;
            printf("%d\n",sum);
        }
    }
    return 0;
}

</span>


C. Hard problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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.

Output

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.

Examples
Input
2
1 2
ba
ac
Output
1
Input
3
1 3 1
aa
ba
ac
Output
1
Input
2
5 5
bbb
aaa
Output
-1
Input
2
3 3
aaa
aa
Output
-1
Note

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个字符串,每个字符串可以倒过来(需要花费a[i[),问你是这n个字符串能否变成字典序排序(每个字符串可以倒过来,也可以为原状态),如果不行输出-1,否则输出费用最小值。


解题思路:一开始觉得就是模拟题,后来错了,然后比赛快结束推出了dp状态转移方程,不过来不及了。

每个字符串只有两种状态,假设S[i]为未反转的状态,s1[i]为反转过来的状态,dp[i][s]---->dp[i][0]表示第 i 个字符串未转换过来前 i 串得到的最优解,dp[i][1]表示第 i 个字符串反转过来前 i 串得到的最优解,那么状态转移方程为:

                        dp[i][0]=dp[i-1][0] (s[i]>=s[i-1])

                       dp[i][0]=dp[i-1][1]  (s[i]>=s1[i-1])

                       dp[i][1]=dp[i-1][0]+a[i] (s[i]>=s[i-1])

                        dp[i][1]=dp[i-1][1]+a[i] (s[i]>=s1[i-1])


<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
#define inf 1e16
using namespace std;
string s[100010];
string s1[100010];
long long dp[100010][2];
int a[100010];
int main()
{
    int n;
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=0;i<=n+1;i++) dp[i][0]=dp[i][1]=inf;
        for(int i=1;i<=n;i++){
            cin>>s[i];
            int len=s[i].size();
            //cout << len << endl;
            for(int j=0,k=len-1;k>=0;k--,j++){
                s1[i]+=s[i][k];
            }
        }

        dp[1][0]=0;
        dp[1][1]=a[1];
        for(int i=2;i<=n;i++){
            int ans=0;
            if(s[i]>=s[i-1]){
                dp[i][0]=min(dp[i][0],dp[i-1][0]);
            }//else ans++;

            if(s[i]>=s1[i-1]){
                dp[i][0]=min(dp[i][0],dp[i-1][1]);
            }//else ans++;

            if(s1[i]>=s[i-1]){
                dp[i][1]=min(dp[i][1],dp[i-1][0]+a[i]);
            }//else ans++;

            if(s1[i]>=s1[i-1]){
                dp[i][1]=min(dp[i][1],dp[i-1][1]+a[i]);
            }//else ans++;

            //if(ans==4) flag=0;
        }
        //if(flag==0){
            //printf("-1\n");
            //continue;
        //}
        printf("%I64d\n",((min(dp[n][0],dp[n][1]))==inf) ? -1 : min(dp[n][0],dp[n][1]));
    }
    return 0;
}
</span>


内容概要:本书《Deep Reinforcement Learning with Guaranteed Performance》探讨了基于李雅普诺夫方法的深度强化学习及其在非线性系统最优控制中的应用。书中提出了一种近似最优自适应控制方法,结合泰勒展开、神经网络、估计器设计及滑模控制思想,解决了不同场景下的跟踪控制问题。该方法不仅保证了性能指标的渐近收敛,还确保了跟踪误差的渐近收敛至零。此外,书中还涉及了执行器饱和、冗余解析等问题,并提出了新的冗余解析方法,验证了所提方法的有效性和优越性。 适合人群:研究生及以上学历的研究人员,特别是从事自适应/最优控制、机器人学和动态神经网络领域的学术界和工业界研究人员。 使用场景及目标:①研究非线性系统的最优控制问题,特别是在存在输入约束和系统动力学的情况下;②解决带有参数不确定性的线性和非线性系统的跟踪控制问题;③探索基于李雅普诺夫方法的深度强化学习在非线性系统控制中的应用;④设计和验证针对冗余机械臂的新型冗余解析方法。 其他说明:本书分为七章,每章内容相对独立,便于读者理解。书中不仅提供了理论分析,还通过实际应用(如欠驱动船舶、冗余机械臂)验证了所提方法的有效性。此外,作者鼓励读者通过仿真和实验进一步验证书中提出的理论和技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值