BestCoder Round #42-1001Shaking hands
来源:互联网 发布:mac os x 10.13 iso 编辑:程序博客网 时间:2024/04/29 12:00
水题。。。
Shaking hands Accepts: 452
Submissions: 583
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
今天是Gorwin的生日,所以她举办了一个派对并邀请她的朋友来参加。她将邀请n个朋友,为了方便,Gorwin把他们从1到n标号。他们之中有一些人已经相互认识,有一些人不认识对方。相互认识的朋友见面之后会握手然后喝一杯香槟。Gorwin想要知道要准备多少杯香槟。你能帮助她吗?
输入描述
多组测试数据(大概30组),每组数据的第一行有一个整数n表示Gorwin要邀请n个朋友来参加她的派对。
接下来n行会给出一个n*n的矩阵,如果a[i][j]是1,那么朋友i和朋友j是相互认识的,否则他们不认识。
请处理到文件末尾。
[参数约定]
所有输入均为整数。
1<=n<=30
0<=a[i][j]<=1
a[i][i]=0;
a[i][j]=a[j][i] for i!=j
输出描述
对于每一个数据,在一行中输出一个整数代表Gorwin总共要准备多少香槟。
输入样例
2
0 0
0 0
3
0 0 1
0 0 0
1 0 0
输出样例
4
8
Hint
对于第二个数据,Gorwin会和她所有的朋友握手,然后喝三杯香槟,她的三个朋友也各喝一杯。朋友1和朋友3相互认识,他们握手,然后各自喝一杯。这样总共要3+3+2=8杯香槟。
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ int n; int i,j,sum; int data[30][30]; while(scanf("%d",&n)!=EOF) { sum=0; memset(data,0,sizeof(int)*900); for(i=0;i<n;i++) for(j=0;j<n;j++) { scanf("%d",&data[i][j]); sum+=data[i][j]; } sum+=2*n; printf("%d\n",sum); } return 0;}
0 0
- BestCoder Round #42-1001Shaking hands
- HDU5232 Shaking hands && BestCoder Round #42
- HDU 5232 Shaking hands
- HDU 5232 Shaking hands
- HDU 5232 Shaking hands
- BestCoder Round #42
- BestCoder Round #42
- BestCoder Round #42
- BestCoder Round #15 1001
- BestCoder Round #49 ($) 1001
- BestCoder Round #55 ($) 1001
- bestcoder Round-#8 1001 Summary
- Bestcoder Round 15# 1001 Love
- BestCoder Round#31 1001 pairs
- Bestcoder Round #48 1001、1002
- HDU BestCoder Round #48 1001
- BestCoder Round #49 ($) 1001 Untitled
- Bestcoder Round#49 1001Untitled
- 第10周项目3-点类派生直线类
- 全排列系列
- 关于android应用程序的入口
- U盘的文件内容如何按照修改时间排列?
- 抽签问题
- BestCoder Round #42-1001Shaking hands
- 画图板的实现
- SGU 106
- ZigZag Conversion
- Java中分割字符串
- 软考专题模块:2014年下半年软件设计师考试上午试题
- 阿里云windows server2012 上用VirtualBox搭建linux环境
- Problem to be solved for MySQL create view
- JAVA字符串用两个分隔符分割的实现