URAL 1194. Handshakes (乱搞)
2015-06-17 11:00
337 查看
1194. Handshakes
Time limit: 1.0 secondMemory limit: 64 MB
A party at the "Prancing Pony" tavern was over and the hobbits were breaking up. At the first crossroad all the company fell into several groups, each of which went its own way. As a matter of courtesy, the hobbits shook each
other's hands before parting (each hobbit shook the hand of each hobbit he was parting with). Each group fell at the next crossroad into several smaller groups (with handshakes of course) and so on. This process continued until single hobbits and married couples
reached their homes. In other words, the groups were splitting up until there were only groups of two or one hobbits left. Your task is to calculate the number of the handshakes made.
Input
Let's numbers the groups of hobbits so that the first group (the one that left the tavern) gets number 1 and other groups get distinct positive integers greater than 1. In the first line of the input there are the total numberof hobbits N and the number of married couples K. These numbers meet the following conditions:2 <
N ≤ 20000; 0 ≤ 2K ≤ N.Each of the next lines of the input starts with the number of the group and the number of groups it fell into. After that there are several pairs of numbers representing the number and size of each new group.
It is guaranteed that if a group no. Y formed as a result of splitting of a group no. X, then the description of the group no. X occurs before the description of the group no. Y. In particular, this means that the description
of the group no. 1 is in the second line of the input. If the group no. Y formed as a result of splitting of the group no. X and its description is absent, then the group no. Y didn't split further.
Output
Output the total number of the handshakes made.Sample
input | output |
---|---|
3 0 1 2 2 2 3 1 2 2 4 1 5 1 | 3 |
Problem Source: Fifth High School Children Programming Contest, Ekaterinburg, March 02, 2002
Tags: none (
hide tags for unsolved problems
)
解析:坑爹的题目,看了半天没看懂。n和k下面那凌乱的数字实则无用。
n个人,互相握手共有:n * (n - 1) / 2
K对***之间不能互相握手: - k
ans = n * (n - 1) / 2 - k
AC代码:
#include <bits/stdc++.h> using namespace std; int main(){ int n, k; scanf("%d%d", &n, &k); printf("%d\n", (n * (n - 1)) / 2 - k); return 0; }
相关文章推荐
- 给eclipse换肤,自己的小窍门。
- 30+程序员,平时都忙些什么事情?平时都想些什么?以后有啥计划?
- linux 命令——30 chown (转)
- 删除软链接和硬链接注意事项
- 用字节流将一个Object对象持久化
- socket参数详解:TcpNoDelay
- js继承 call apply
- bootstrap3.css对自定义css的影响
- CXF的SOAPHandler处理 日志
- win32 dll导出类的使用
- OSSIM的Session存储问题研究
- OSSIM的Session存储问题研究
- 黑马程序员——java基础——网络编程
- 简介AngularJS中使用factory和service的方法
- js cookie 的创建读取删除
- 关于combobox的下拉选择与键盘输入的统一
- <PY>生猴子程序
- Spark-sql 运行提示too many open files
- JAVA中的一些基本概念
- Centos6.5使用yum安装mysql——快速上手必备