现在的位置: 首页 > 综合 > 正文

Codeforces Round #239 (Div. 2)

2018年05月03日 ⁄ 综合 ⁄ 共 6991字 ⁄ 字号 评论关闭
A. Line to Cashier
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.

There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th
cashier already has ki people.
The j-th person standing in the queue to the i-th
cashier has mi, j items
in the basket. Vasya knows that:

  • the cashier needs 5 seconds to scan one item;
  • after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.

Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.

Input

The first line contains integer n (1 ≤ n ≤ 100) —
the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100),
where ki is
the number of people in the queue to the i-th cashier.

The i-th of the next n lines contains ki space-separated
integers: mi, 1, mi, 2, ..., mi, ki (1 ≤ mi, j ≤ 100) —
the number of products thej-th person in the queue for the i-th
cash has.

Output

Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.

Sample test(s)
input
1
1
1
output
20
input
4
1 4 3 2
100
1 2 2 3
1 9 1
7 8
output
100
Note

In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds.
He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds
for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.

正常模拟就好

#include <stdio.h>
#include <string.h>
const int N = 101;
int a[N], num[N], sum[N];

int main()
{
    int n, tem;
    int minn = 0x3f3f3f;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &num[i]);
    }
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= num[i]; j++)
        {
            scanf("%d", &tem);
            sum[i] += tem;
        }
        sum[i] = sum[i] * 5 + num[i] * 15;
    }

    for (int i = 1; i <= n; i++)
        minn = minn < sum[i] ? minn : sum[i];

    printf("%d\n", minn);
    return 0;
}

B. Garland
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored
sheets of paper, the area of each sheet is 1 square meter.

The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can
arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.

Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​m pieces of paper in the garland. Calculate what the
maximum total area of ​​the pieces of paper in the garland Vasya can get.

Input

The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000)
small English letters ("a"..."z").
Each letter means that Vasya has a sheet of paper of the corresponding color.

The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000)
small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

Output

Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.

Sample test(s)
input
aaabbac
aabbccac
output
6
input
a
z
output
-1
Note

In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color aand
cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.

In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color z.

开始理解错题意,认为输出能用到的最大纸张数,(主要是没理解把C平均分成三份的意思)。就算只有B中有的字符A中没有也要输出-1.。。。

#include <stdio.h>
#include <string.h>

const int N = 1010;
char A[N], B[N];
int An[N], Bn[N];

int main()
{
    scanf("%s%s", A, B);
    int lena = strlen(A);
    int lenb = strlen(B);
    memset(An, 0, sizeof(An));
    memset(Bn, 0, sizeof(Bn));
    for (int i = 0; i < lena; i++)
    {
        An[ A[i] - 'a']++;
    }
    for (int i = 0; i < lenb; i++)
    {
        Bn[ B[i] - 'a']++;
    }

    int ans = 0;
    for (int i = 0; i < 26; i++)
    {
        if (Bn[i])
        {
            if (!An[i]) {ans = 0; break;}
            if (An[i] <= Bn[i]) ans += An[i];
            else ans += Bn[i];
        }
    }
    printf("%d\n", ans == 0 ? -1 : ans);
    return 0;
}
C. Triangle
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a right triangle with legs of length a and b.
Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output
the appropriate coordinates of vertices.

Input

The first line contains two integers a, b (1 ≤ a, b ≤ 1000),
separated by a single space.

Output

In the first line print either "YES" or "NO" (without the quotes)
depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in
their absolute value.

Sample test(s)
input
1 1
output
NO
input
5 5
output
YES
2 1
5 5
-2 4
input
5 10
output
YES
-10 4
-2 -2
1 2

题意: 给出直角三角形的两条边, 能否求出一个直角三角形, 使其三边和坐标轴都不平行, 且三个顶点的坐标为整数

解题思路: 开始的时候觉得试剂盒题不会;看了别人的代码,原来暴力就好(为什么呢?a,b < 1000)
暴力解点看是不是整数就好了:-D
#include <stdio.h>
#include <math.h>


const double eps = 1e-6;
double abs(const double& a)
{
    return a >= 0 ? a : -a;
}


bool eq(const double& a, const double& b)
{
    return abs(a - b) <= eps;
}
int main()
{
    int L, R;
    double Lx, Ly, Rx, Ry;
    scanf("%d%d", &L, &R);
    for (int i = 1; i < L; i++)
    {
        Ly = sqrt(L * L*1.0 - i * i*1.0);
        if (Ly == (int)Ly)
        {
            Rx = 1.0 * R / L * Ly;
            if (eq(Rx, (int)Rx))
            {
                Ry = sqrt(R * R*1.0 - Rx * Rx);
                if (Ry == (int)Ry)
                {
                    Lx = (int)sqrt(L * L*1.0 - Ly * Ly);
                    Ry = (int)sqrt(R * R*1.0 - Rx * Rx);
                    if (eq(Ly,Ry)) continue;
                    printf("YES\n0 0\n");
                    printf("-%.0lf %0.lf\n%.0lf %.0lf\n", Lx, Ly, Rx, Ry);
                    return 0;


                }
            }


        }
    }
    printf("NO\n");
}
被精度问题搞死了
D. Long Path
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1).
Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one.

The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n),
someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room numberpi,
where 1 ≤ pi ≤ i.

In order not to get lost, Vasya decided to act as follows.

  • Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1.
  • Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses
    the second portal (it leads to room pi),
    otherwise Vasya uses the first portal.

Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end.

Input

The first line contains integer n (1 ≤ n ≤ 103) —
the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i).
Each pidenotes
the number of the room, that someone can reach, if he will use the second portal in the i-th room.

Output

Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7).

Sample test(s)
input
2
1 2
output
4
input
4
1 1 2 3
output
20
input
5
1 1 1 1 1
output
62

题意:一个屋子有两个门, 想从第一个屋子走到第n+1个屋子, 每进一个屋子打一个叉:1,如果叉的个数为奇数, 传送到pi  2:,偶数的话走到i+1。

求步数。

抱歉!评论已关闭.