Yandex.Algorithm 2016 Qualification Round 题解(待补)

  • Orthography
  • Voice AlertsOne of the most important features in YandexNavigator is the voice alert of the next manoeuvre the application kindly warns the driver about a turn they must make some time in advance So people dont have to constantly check the screen
  • Table Tennis Tournament

Orthography

给n个字符串,输出任意一个字符串,它与其他每个字符串最多相差1个字符

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) 
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
int n;
string s[2000];
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);

    cin>>n;
    For(i,n) cin>>s[i];
    int len=s[1].length();
    For(i,n) {
        int flag=0;
        For(j,n) {
            flag=0;
            Rep(k,len) if (s[i][k]!=s[j][k]) flag++;
            if (flag>1) break;
        }
        if (flag>1) continue;
        else {
            cout<<s[i]<<endl; return 0;
        } 
    }


    return 0;
}

Voice AlertsOne of the most important features in Yandex.Navigator is the voice alert of the next manoeuvre: the application kindly warns the driver about a turn they must make some time in advance. So people don’t have to constantly check the screen.

In order for the driver to have time to hear the alert and take appropriate actions, the alert needs to be started beforehand. Of course, the alert should not start too early, because if there’s too much time between the alert and the actual place of manoeuvre, the driver can forget about it or just miss the turn.
For the sake of simplicity, we assume that all the alerts have the form “after X meters turn right”, where X is a positive integer for which a voice pronunciation is recorded (the real application can warn the driver about different kinds of manoeuvres, not only right turns). Could you develop an algorithm that can choose such alert that the application needs to start pronouncing the alert as late as possible, in order not to distract the driver unnecessarily?
Consider the detailed mathematical model of the problem. We assume that the driver moves along a straight line at a constant speed of V meters per second. There is a list of integers Xi: the distances in meters for which there exists a recorded voice pronunciation. Each Xi corresponds to a real number ti: the duration of a voice recording of number Xi in seconds. Additionally, you are given a real number Tphrase: the total time it takes to pronounce the fixed part of the alert, that is, the words “after” and “meters turn right”. You are required to find the minimal number D, the distance to the start of the manoeuvre, and also an index i such that, starting from the time at which the driver will be in D meters from the place of manoeuvre, while driving at a constant speed V in time ti + Tphrase, the driver would be exactly Xi meters before the actual place of the manoeuvre. The indices of Xi start from 1.

阅读理解题。。

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) 
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
int main()
{
// freopen("B.in","r",stdin);
// freopen(".out","w",stdout);

    double v,T;
    cin>>v>>T; 
    int n=read();
    double ans;
    int p;
    For(i,n) {
        double x,t;
        cin>>x>>t;
// cout<<x+v*(t+T)<<endl;
        if (i==1) {
            ans=x+v*(t+T); p=1;
        } else if (ans>x+v*(t+T)){

            ans=x+v*(t+T); p=i;
        }
    } 
    cout<<setiosflags(ios::fixed)<<setprecision(5); 
    cout<<ans<<' '<<p<<endl;

    return 0;
}

Table Tennis Tournament

The Minsk’s office held a table tennis tournament. N employees participated in the tournament. During the tournament, each of them played exactly one match against every other. The winner of each match received 2 points, and the loser got 1 point. There are no ties in table tennis. At the end of the tournament, the scores of each participant were summed up, and it turned out that all the participants scored different number of points. Roma, Sergei and Alex are interested whether it is likely that the result of the tournament will have such a property.
For convenience, enumerate the employees by integers from 1 to N. Suppose that probabilities pij are known: the employee with the number i will win the match against an employee j with probability pij. Find the probability that after all the N(N-1)/2 matches, all participants will have different number of points.

显然它们分别胜利0,1,2,..,n-1局
赢1局的只打赢赢0局的
赢2局的只打赢赢0,1局的
..etc

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p]) 
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (100)
double a[MAXN][MAXN];
int c[100];
int main()
{
// freopen("C.in","r",stdin);
// freopen(".out","w",stdout);

    int n=read();
    For(i,n) c[i]=i;
    For(i,n) For(j,n) cin>>a[i][j];
    double tot=0;
    do {
        double ans=1;
        For(i,n) Fork(j,i+1,n) {
            ans*=a[c[i]][c[j]];
        } 

        tot+=ans;
    } while (next_permutation(c+1,c+1+n));

    printf("%.10lf\n",tot);
    return 0;
}

你可能感兴趣的:(Yandex.Algorithm 2016 Qualification Round 题解(待补))