HDU 5232 Shaking hands

来源:互联网 发布:蓝月传奇翅膀数据 编辑:程序博客网 时间:2024/03/28 23:37

Shaking hands

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 444    Accepted Submission(s): 365


Problem 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
20 00 030 0 10 0 01 0 0
 

Sample Output
48
Hint
For the second case, Gorwin will shake hands with all her friends, then Gorwin drink three cups of champagne, each friends drink one cup. Friend 1 and friend 3 know each other,every of them drinks one cup again. So the total cups is 3+3+2=8.
 
超级简单的一道题,只不过刚开始就看后面数学题了,没读,,,
大体题意:
输入一个n,表示主人公认识n个人,矩阵a[i][j] = 1表示i与j认识,等于0表示不认识,每每认识的两个人就喝一杯酒,总共2杯酒,
问所需几杯酒。
思路:
直接让sum = 2*n,碰到一个1加2就行了!

代码如下:

#include<iostream>#include<cstdio>#include<map>#include<set>#include<stack>#include<queue>#include<vector>#include<string>#include<cstring>#include<cmath>#include<cstdlib>#include<cctype>#include<algorithm>#define mem(x) memset(x,0,sizeof(x));#define mem1(x) memset(x,-1,sizeof(x));using namespace std;const int maxn = 10000 + 10;const int maxt = 100 + 10;const double eps = 1e-8;const double pi = acos(-1.0);const int INF = 1e8;typedef long long ll;typedef unsigned long long llu;int main(){    int n;    while(cin >> n){        int a[maxt][maxt];        int sum = 2*n;        for (int i = 0; i < n; ++i)            for (int j = 0; j < n; ++j)                cin >> a[i][j];        for (int i =0; i < n; ++i){            for (int j =0;j <=i;++j){                if (a[i][j])sum+=2;            }        }        cout << sum << endl;    }    return 0;}


0 0
原创粉丝点击