AIM Tech Round (Div. 2) 解题报告

624A-Save Luke

Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1 and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.

Input
The first line of the input contains four integers d, L, v1, v2 (1 ≤ d, L, v1, v2 ≤ 10 000, d < L) — Luke’s width, the initial position of the second press and the speed of the first and second presses, respectively.

Output
Print a single real value — the maximum period of time Luke can stay alive for. Your 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 .

input
2 6 2 2
output
1.00000000000000000000

input
1 9 1 2
output
2.66666666666666650000

题目链接:cf-624A

题目大意:两个人面向而行,初始距离为l,速度分别为v1,v2.若两人相隔距离为d则结束。问至结束需要多少时间

题目思路:水题

以下是代码:

#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;

typedef long long ll;

int main(){
    int d,l,v1,v2;
    cin >> d >> l >> v1 >> v2;
    double time = (l - d) * 1.0 / (v1 + v2);
    printf("%.20f\n",time);
    return 0;
}

624B-Making a String【贪心】

You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:

the i-th letter occurs in the string no more than ai times;
the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.

Input
The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet.

The next line contains n integers ai (1 ≤ ai ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.

Output
Print a single integer — the maximum length of the string that meets all the requirements.

input
3
2 5 5
output
11

input
3
1 1 2
output
3

题目链接:cf-624B

题目大意:有n个字母组成一个最长字符串,需要满足下列条件:

  1. 第i个字母不超过a[i]次
  2. 出现过的字母,出现次数各不同

题目思路:贪心,详见代码。

#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;

typedef long long ll;
ll a[30];
bool cmp(ll x,ll y)
{
    return x > y;
}
map <ll,int> mp;
int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a,a + n,cmp);
    mp[a[0]] = 1;
    ll ans = a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i] == 0) break;
        if (mp[a[i]] == 1)
        {
            a[i]--;
            i--;
        }
        else
        {
            mp[a[i]] = 1;
            ans += a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

624C-Graph and String

One day student Vasya was sitting on a lecture and mentioned a string s1s2… sn, consisting of letters “a”, “b” and “c” that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:

G has exactly n vertices, numbered from 1 to n.
For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs “a”-“b” and “b”-“c” are neighbouring, while letters “a”-“c” are not.
Vasya painted the resulting graph near the string and then erased the string. Next day Vasya’s friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya’s adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.

Input
The first line of the input contains two integers n and m — the number of vertices and edges in the graph found by Petya, respectively.

Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.

Output
In the first line print “Yes” (without the quotes), if the string s Petya is interested in really exists and “No” (without the quotes) otherwise.

If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters “a”, “b” and “c” only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.

input
2 1
1 2
output
Yes
aa

input
4 3
1 2
1 3
1 4
output
No

题目链接:cf-624C

题目大意:存在a,b,c三种字母,给出n个点,m条边。问这幅图是否满足以下条件

a-a, a-b, b-b, b-c, c-c 能够相连。

输出任一满足条件的字符串

题目思路:

  1. 首先我们可以知道,b点可以与a,b和c相连即图上任一点相连。所以点b的度数为n-1。所以,先将度数为n-1的点填充为b
  2. 任取一点假设为a点。则所有与a相连的点为a,不与a相连的点填充为c

注意:需要有一个检查步骤。即:相连两个点,差值 ≤ 1;不相连的两个点差值 > 1 (a 与 c点)

以下是代码:

#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;

typedef long long ll;
int g[505][505];
int cor[505];
int edge[505];
int n,m;
bool check()
{
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j) continue;  //注意 
            if (g[i][j] == 1 && abs(cor[i] - cor[j]) > 1) return 0;
            if (g[i][j] == 0 && abs(cor[i] - cor[j]) <= 1) return 0;
        }
    }
    return 1;
}
int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int u,v;
        cin >> u >> v;
        g[u][v] = 1;
        g[v][u] = 1;
        edge[u]++;  //各点度数 
        edge[v]++;
    }
    int first = 1,poa = 0;
    for (int i = 1; i <= n; i++)
    {
        if (edge[i] == n - 1) cor[i] = 2;  //可以确定的是b点一定和所有点相连 
        if (edge[i] != n - 1 && first) cor[i] = 1,first = 0,poa = i;  //任意设立一个点为a 
    }
    if (first)  //找不到别的点(A / C) 
    {
        cout << "Yes\n";
        for (int i = 0; i < n; i++) cout << "b";
        cout << endl;
    } 
    else
    {
        for (int i = 1; i <= n; i++)
        {
            if (cor[i] != 2 && i != poa)  //注意 i != poa
            {
                if (g[poa][i]) cor[i] = 1; //如果该点和a点相连则为a
                else cor[i] = 3;  //否则为c点 
            }
        }
        int flag = check();
        if (flag)
        {
            cout << "Yes\n";
            for (int i = 1; i <= n; i++)
            {
                if (cor[i] == 1) cout << "a";
                if (cor[i] == 2) cout << "b";
                if (cor[i] == 3) cout << "c";
            }
            cout << endl;
        }
        else cout << "No\n";
    }
    return 0;
}

你可能感兴趣的:(codeforces)