Count the Sheep

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 686    Accepted Submission(s): 295

Problem Description
Altough Skipping the class is happy, the new term still can drive luras anxious which is of course because of the tests! Luras became worried as she wanted to skip the class, as well as to attend the BestCoder and also to prepare for tests at the same time.



However, As the result of preparing for tests, luras had no time to practice programing. She didn't want to lose her rating after attending BC. In the end, she found BCround92's writer snowy_smile for help, asking him to leak her something.



Snowy_smile wanted to help while not leaking the problems. He told luras, the best thing to do is to take a good rest according to the following instructions first.



"Imagine you are on the endless grassland where there are a group of sheep. And n sheep of them are silent boy-sheep while m sheep are crying girl-sheep. And there are k friend-relationships between the boy-sheep and girl-sheep.Now You can start from any sheep,
keep counting along the friend relationship. If you can count 4 different sheep, you will exceed 99% sheep-counters and fall asleep."



Hearing of the strange instructions, luras got very shocked. Still, she kept counting. Sure enough, she fell asleep after counting 4 different sheep immediately. And, she overslept and missed the BestCoder in the next day. At a result, she made it that not
losing her rating in the BCround92!!!



However, you don't have the same good luck as her. Since you have seen the 2nd problem, you are possible to have submitted the 1st problem and you can't go back.



So, you have got into an awkward position. If you don't AC this problem, your rating might fall down.



You question is here, please, can you tell that how many different 4-sheep-counting way luras might have before her sleep?



In another word, you need to print the number of the "A-B-C-D" sequence, where A-B, B-C, C-D are friends and A,B,C,D are different.
 
Input
The first line is an integer T which indicates the case number.



and as for each case, there are 3 integers in the first line which indicate boy-sheep-number, girl-sheep-number and friend-realationship-number respectively.



Then there are k lines with 2 integers x and y in each line, which means the x-th boy-sheep and the y-th girl-sheep are friends.



It is guaranteed that——



There will not be multiple same relationships.



1 <= T <= 1000



for 30% cases, 1 <= n, m, k <= 100



for 99% cases, 1 <= n, m, k <= 1000



for 100% cases, 1 <= n, m, k <= 100000
 
Output
As for each case, you need to output a single line.



there should be 1 integer in the line which represents the number of the counting way of 4-sheep-sequence before luras's sleep.
 
Sample Input
3
2 2 4
1 1
1 2
2 1
2 2
3 1 3
1 1
2 1
3 1
3 3 3
1 1
2 1
2 2
 
Sample Output
8
0
2
找规律的题目
先算出来开端是男孩是情况ans,最后的结果是ans*2
四个关系 男-女-男-女
就像一颗只有四层的树,最后一层叶子节点的个数就是答案
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector> using namespace std;
typedef long long int LL;
const int maxn=1e5;
int n,m,k;
vector<int> a[maxn+5];
vector<int> b[maxn+5];
int aa[maxn+5];
int bb[maxn+5];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
int x,y;
for(int i=1;i<=n;i++)
a[i].clear();
for(int i=1;i<=m;i++)
b[i].clear();
memset(aa,0,sizeof(aa));
memset(bb,0,sizeof(bb));
for(int i=1;i<=k;i++)
{
scanf("%d%d",&x,&y);
a[x].push_back(y);
b[y].push_back(x);
aa[x]++;
bb[y]++;
}
LL ans=0;
for(int i=1;i<=n;i++)
{
LL res=0;
for(int j=0;j<aa[i];j++)
{
res+=(bb[a[i][j]]-1);
}
ans+=res*(aa[i]-1);
}
printf("%lld\n",ans*2);
}
return 0;
}



 

HDU 6016 Count the Sheep的更多相关文章

  1. (bc 1002)hdu 6016 count the sheep

    Count the Sheep Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. HDU - 6016 Count the Sheep 二分图+思维

    Count the Sheep 题意: 问题描述 开学翘课固然快乐,然而也有让呃喵抓狂的事,那当然就是考试了!这可急坏了既要翘课又想要打BC还要准备考试的呃喵. 呃喵为了准备考试没有时间刷题,想打BC ...

  3. hdu 6016 Count the Sheep(思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016 题意:给定男羊和女羊的朋友关系,即给定一个图,问从任意一只羊开始连续数四只不相同的羊的方法数. ...

  4. HDU 3336 Count the string(KMP的Next数组应用+DP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. Count the Sheep 思维题

    Altough Skipping the class is happy, the new term still can drive luras anxious which is of course b ...

  6. HDU 5901 Count primes 论文题

    Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...

  7. hdu 3336 Count the string -KMP&dp

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  8. HDU 6470 Count 【矩阵快速幂】(广东工业大学第十四届程序设计竞赛 )

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6470 Count Time Limit: 6000/3000 MS (Java/Others)    ...

  9. HDU 4372 Count the Buildings

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

随机推荐

  1. e670. 缓冲图像转换为图像

    // This method returns an Image object from a buffered image public static Image toImage(BufferedIma ...

  2. C++ 数据封装

    C++ 数据封装所有的 C++ 程序都有以下两个基本要素: 程序语句(代码):这是程序中执行动作的部分,它们被称为函数.程序数据:数据是程序的信息,会受到程序函数的影响.封装是面向对象编程中的把数据和 ...

  3. (转)引用---FFMPEG解码过程

    视频播放过程 首先简单介绍以下视频文件的相关知识.我们平时看到的视频文件有许多格式,比如 avi, mkv, rmvb, mov, mp4等等,这些被称为容器(Container), 不同的容器格式规 ...

  4. 【Java面试题】39 Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?

    1.什么是Set?(what) Set是Collection容器的一个子接口,它不允许出现重复元素,当然也只允许有一个null对象. 2.如何来区分重复与否呢?(how) “ 用 iterator() ...

  5. linux,shell中if else if的写法,if elif

    需求描述: 在写shell脚本的过程中,用到了if else的写法,突然有多个参数需要判断 那么就想到了if else if的用法,于是进行如下的测试. 测试过程: 1.写如下的测试脚本,进行多个值的 ...

  6. [ML] I'm back for Machine Learning

    Hi, Long time no see. Briefly, I plan to step into this new area, data analysis. In the past few yea ...

  7. Visual Studio使用技巧,创建自己的代码片段

    1.代码片段的使用示例 在编写代码中常会使用代码片段来提高我们的编写代码的效率,如:在Visual Studio中编写一个 for(int i = 0; i < length;i++) { } ...

  8. Effective C++ Item 17 Store newed objects in smart pointer in standalone statements

    If you trying to do multiple things in one statement, you should think carefully abnormal behavior e ...

  9. POJ 1018 Communication System(树形DP)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  10. 【RF库Collections测试】Get Slice From List

    Name:Get Slice From ListSource:Collections <test library>Arguments:[ list_ | start=0 | end=Non ...