1869. New Year Cruise



原题链接: 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  a ij. The element  a ij is the number of people who have bought a ticket from station  i to station  j (0 ≤  a ij ≤ 1 000;  a ii = 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

input output
3
0 180 180
0 0 180
360 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值