Shaking hands

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5232

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

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.

题意

今天是Gorwin的生日,所以她举办了一个派对并邀请她的朋友来参加。她将邀请n个朋友,为了方便,Gorwin把他们从1到n标号。他们之中有一些人已经相互认识,有一些人不认识对方。相互认识的朋友见面之后会握手然后喝一杯香槟。Gorwin想要知道要准备多少杯香槟。你能帮助她吗?

题解:

给你的图里面有多少个1,ans就加多少

然后再加n,再乘2就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int g[][];
int main()
{
//freopen("test.txt","r",stdin);
int n;
while(scanf("%d",&n)!=EOF)
{
memset(g,,sizeof(g));
for(int i=;i<n;i++)
for(int j=;j<n;j++)
g[i][j]=read();
int ans=;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(g[i][j])
{
ans++;
g[i][j]=;
g[j][i]=;
}
}
}
cout<<(ans+n)*<<endl;
}
}

hdu 5232 Shaking hands 水题的更多相关文章

  1. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  2. HDU 4950 Monster (水题)

    Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...

  3. HDU 4813 Hard Code 水题

    Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  4. HDU 4593 H - Robot 水题

    H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  5. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  6. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  7. HDU - 1716 排列2 水题

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. HDU—2021-发工资咯(水题,有点贪心的思想)

    作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵  但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每 ...

  9. hdu 5753 Permutation Bo 水题

    Permutation Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

随机推荐

  1. (4)剑指Offer之链表相关编程题

    一 链表中倒数第k个节点 题目描述: 输入一个链表,输出该链表中倒数第k个结点 问题分析: 一句话概括: 两个指针一个指针p1先开始跑,指针p1跑到k-1个节点后,另一个节点p2开始跑,当p1跑到最后 ...

  2. php中的转义函数

    <?php parse_url 解析URL, 返回各组成部分 urlencode/urldecode url编码/解码 htmlentities 将字符串转化为html实体 htmlentiti ...

  3. queue_delayed_work和queue_work区别 (转http://blog.csdn.net/dosculler/article/details/7968101)

    queue_delayed_work和queue_work 一.参考文献: 1)http://www.linuxidc.com/Linux/2011-08/41655.htm queue_delaye ...

  4. python使用unittest模块selenium访问斗鱼获取直播信息

    import unittest from selenium import webdriver from bs4 import BeautifulSoup as bs class douyu(unitt ...

  5. 72.Edit Distance---dp

    题目链接:https://leetcode.com/problems/edit-distance/description/ 题目大意:找出两个字符串之间的编辑距离(每次变化都只消耗一步). 法一(借鉴 ...

  6. Nginx源码分析-ngx_module_s结构体

    该结构体是整个Nginx模块化架构最基本的数据结构体.它描述了Nginx程序中一个模块应该包括的基本属性,在tengine/src/core/ngx_conf_file.h中定义了该结构体 struc ...

  7. 对于ntp.conf的理解

    允许与我们的时间源同步时间,但是不允许源查询或修改这个系统上的服务. # Permit time synchronization with our time source, but do not # ...

  8. 设置或者获取CheckboxList控件的选中值

    1.设置CheckBoxList选中的值 /// <summary> /// 设置CheckBoxList中哪些是选中了的 /// </summary> /// <par ...

  9. Java学习(if wihle switch for语句)

    一.if语句 定义:if语句是指如果满足某种条件,就进行某种处理. 语句: if (条件语句){ 执行语句; …… } 上述格式中,判断条件是一个布尔值,当判断条件为true时,{}中的执行语句才会执 ...

  10. linux网络管理----网络命令

    1 Linux网络命令之网络环境查看命令  ifconfig  2 Linux网络命令之网络测试命令  telnet 基本已经被ssh替代了,telnet是明文传递,不安全