HDU 5232 Shaking hands

Description

Today is Gorwin’s birthday, so she holds a party and invites her friends to participate. She will invite n friends, for convenience, Gorwin numbers them from 1 to n. Some of them have known each other, But some of them have not. Those friends whose have known each other will shake hands with each other, and drink one cup of champagne. Gorwin wants to know how many cups of champagne she should prepare. Can you help her?
 

Input

Multiple test cases (about 30), the first line of each case contains an integer n which indicates Gorwin will invite n friends to her party. 

Next n lines will give a n*n matrix, if a[i][j] is 1, then friend i and friend j have known each other, otherwise they have not known each other. 

Please process to the end of file. 

[Technical Specification] 

All input entries are integers. 

1<=n<=30 

0<=a[i][j]<=1 

a[i][i]=0; 

a[i][j]=a[j][i] for i!=j 
 

Output

For each case, output an integer which denotes total cups of champagne Gorwin should prepare in a single line.
 

Sample Input

     
     
     
     
2 0 0 0 0 3 0 0 1 0 0 0 1 0 0
 

Sample Output

     
     
     
     
4 8

题意:Gorwin要和每个客人都喝一杯香槟n*2     其他认识的客人之间也要互相敬一杯酒(标记1为认识)

#include <iostream>
#include <string.h>
#include <map>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
    int a[35][35],n;//自己要与每个人喝酒 2*n
    while(scanf("%d",&n)!=EOF)
    {
        int num=0,SUM=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
        {
            scanf("%d",&a[i][j]);
            if(a[i][j]==1) num++;
        }
        SUM=n*2+num;
        printf("%d\n",SUM);
    }
    return 0;
}


你可能感兴趣的:(HDU 5232 Shaking hands)