1869. New Year Cruise

来源:互联网 发布:2016淘宝刷单违规处罚 编辑:程序博客网 时间:2024/06/06 02:53



原题链接: http://acm.timus.ru/problem.aspx?space=1&num=1869



In the life of Russian people there is always a place for a holiday! Even more so when several causes for celebration follow each other — New Year, Orthodox Christmas, Old New Year… People celebrate these holidays in different ways. Some of them like to be together with their family and friends, while others prefer to go for a travel. The company “Siberian Railroads” decided to combine these two variants by introducing a special cruise train “Booze” traveling along the route Vladivostok–Moscow–Vladivostok. The train would cruise once in a year only, during the New Year holidays. It would be adapted for celebrating each of the holidays up until the following holiday or until arriving to the destination.
When the company started selling tickets for the train, they turned out to be in great demand. The sale was stopped on the third day because a train for all those wishing to go on the cruise would be too long to fit any station. The company's managers calculated the number of tickets sold for the travel between each pair of stations, and they wanted to know the number of cars in the train sufficient to accommodate all the passengers.

Input

The first line contains the number n of stations where the train stops when traveling in one direction (2 ≤ n ≤ 100). The stations are numbered from 1 to n in the order the train passes them. Vladivostok is numbered 1 and Moscow is numbered n. In the following n lines you are given an n × n matrix with integer elements aij. The element aij is the number of people who have bought a ticket from station i to station j (0 ≤ aij ≤ 1 000; aii = 0); these people will board the train traveling from Vladivostok to Moscow if i < j and the train traveling in the opposite direction if i > j.

Output

Output the minimal number of cars in the train that is sufficient to accommodate all the passengers. There are exactly 36 seats in each car.

Sample

inputoutput
30 180 1800 0 180360 0 0
10
Problem Author: Denis Dublennykh
Problem Source: Open Ural FU Championship 2011




/* * ACM Timus Online Judge Contest 15 October 2011 * Problem H - New Year Cruise */#include <cstdio>#define MAX(a, b)               ((a) > (b) ? (a) : (b))int N, A[100][100];int main(){#ifndef ONLINE_JUDGE        freopen("input.txt", "rt", stdin);#endif        int i, j, k, max;        scanf("%d", &N);        for (i = 0; i < N; i++)                for (j = 0; j < N; j++)                {                        scanf("%d", &A[i][j]);                };        for (i = 0; i < N; i++)                for (j = 0; j < N; j++)                {                        if (A[i][j] == 0)                                continue;                        // Vladi -> Moscow                        if (i < j && j - i > 1)                        {                                for (k = i; k < j; k++)                                {                                        A[k][k + 1] += A[i][j];                                }                        }                        // Moscow -> Vladi                        else if (i > j && i - j > 1)                        {                                for (k = i; k > j; k--)                                {                                        A[k][k - 1] += A[i][j];                                }                        }                };        // get maximum for each pair of stations        max = 0;        for (i = 0; i < N - 1; i++)        {                if (MAX(A[i][i + 1], A[i + 1][i]) > max)                {                        max = MAX(A[i][i + 1], A[i + 1][i]);                }        }        if (max % 36 == 0)                max /= 36;        else                max = 1 + max / 36;        printf("%d", max);        return 0;}


原创粉丝点击