Light Yard 2261: flower

2261: flower

Time Limit: 1 Sec Memory Limit: 128 MB
Commits: 271 Resolved: 167
[ Commit ][ Status ][ Discussion Board ][Assert By: admin ]

Topic description

It's Teacher's Day again, and there are n children who plan to visit Teacher Hua.
Of course, you have to buy flowers when you go to see the flower teacher. However, some local (xue) ho (ba) bought too many flowers, which made other children very embarrassed, so the children came up with a solution:

They plan not to directly tell Teacher Hua how many flowers each person bought, but to encrypt it in some way (too naive), the encryption method is as follows:

Suppose the i-th child sends A i flowers (A i  > 0), then T(j,k) is defined as follows

T (j, k) = A j  + A k  (j ≠ k)

T (j, k) = 0 (j = k)

Then they tell Teacher Hua all T(j,k).

Of course, the kind flower teacher doesn't care about who sent how many flowers, but you are curious to know which children are more earthy (xue) and proud (ba).

enter

The first line contains a positive integer n. (2 <= n <= 1000, 2 <= T(j,k) <= 1000)

The next n lines each contain n non-negative integers T(j,k).

output

Output a line of n positive integers A j separated by spaces, if there are multiple possibilities to output the smallest sum of all unknowns.

sample input

40 3 6 73 0 5 66 5 0 97 6 9 0

Sample output

2 1 4 5

source

#include<stdio.h>  
int a[1010][1010], s[1010];  
intmain()  
{  
    int n, years;  
    while (~scanf("%d", &n))  
    {  
        for (int i = 0; i < n; i++)  
            for (int j = 0; j < n; j++)  
                scanf("%d", &a[i][j]);  
        if (n == 2)  
        {  
            printf("1 %d", a[0][1] - 1);  
            continue;  
        }  
        s[0] = 0;  
        for (int i = 2; i <= n; i++)  
            s[i - 1] = s[i - 2] + a[i % n][i - 1] - a[i % n][i - 2];  
        for (int i = 1; i <= 500; i++)  
        {  
            if (s[0] + s[1] + 2 * i == a[1][0])  
            {  
                years = i;  
                break;  
            }  
        }  
        for (int i = 0; i < n; i++)  
            printf("%d ", s[i] + ans);  
        printf("\n");  
    }  
    return 0;  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324679008&siteId=291194637