Count the Sheep

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

Total Submission(s): 484    Accepted Submission(s): 212

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

Count the Sheep

 Accepts: 227
 Submissions: 805
 Time Limit: 3000/1500 MS (Java/Others)
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
开学翘课固然快乐,然而也有让呃喵抓狂的事,那当然就是考试了!这可急坏了既要翘课又想要打BC还要准备考试的呃喵。
呃喵为了准备考试没有时间刷题,想打BC又不想跌分,只得求助于BCround92的出题人snowy_smile,让他说点什么 ~~>_<~~。
snowy_smile实在没有办法,但是又不好意思透题,只好告诉呃喵,当务之急是好好休息。
"如果你按照下面这个办法睡着,那么第二天就绝对不会在BC的赛场上跌分——
想象一片一望无际、广阔无边的青青草原,草原上住着一群羊,包括n只沉默的男羊和m只流泪的女羊,在男羊和女羊之间,存在k个朋友关系。
现在你可以以任意一只羊为起点,顺着朋友关系数下去。如果能够连续数4只各不相同的羊,就能超过99%的数羊者,成功入睡。"
呃喵听后十分震惊,但她还是听话地数下去,果然,数到第4只羊就睡着了,并一口气睡过了头,成功地错过了第二天的BestCoder,真的不会在BC的赛场上跌分啦!
然而你,可就没有这么好的运气了,你既然看到了这第二题,自然一般已有提交,已经无法回头了。
面对"不AC这题就可能跌分"窘境的你,需要说出,呃喵在睡前可能有多少种不同的数羊序列。
即输出"A-B-C-D"这样序列的方案数,满足A-B、B-C、C-D是朋友关系且A、B、C、D各不相同。
输入描述
第一行输入数据组数T
对于每组数据,第一行有三个整数n, m, k,表示n只男羊编号分别为1~n,m只女羊编号分别为1~m,并且存在k个朋友关系。
接下来给出k行,每行给出两个数x y,表示第x只男羊和第y只女羊是朋友。 数据保证——
不会给出重复的朋友关系
1 <= T <= 1000
对于30%的数据,1 <= n, m, k <= 100
对于99%的数据,1 <= n, m, k <= 1000
对于100%的数据,1 <= n, m, k <= 100000
输出描述
对于每组数据,输出一行,该行包含一个整数,表示呃喵睡觉前可能数了哪4只羊的序列的方案数。
输入样例
(为了方便阅读,样例输入中数据组间中会额外添加一行空行)
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
输出样例
8
0
2
Hint
第一组样例:(b1-g1-b2-g2) (b1-g2-b2-g1) (b2-g1-b1-g2) (b2-g2-b1-g1) (g1-b1-g2-b2) (g1-b2-g2-b1) (g2-b1-g1-b2) (g2-b2-g1-b1) 共8种合法
//在这个二分图中,我们枚举每一段男女关系,
//然后由男的延伸出一个女的,女的延伸出一个男的,
//这样就可以组成一个四人组了.
//最后的结果乘二就行。
#include<queue>
#include<stack>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=100000+10; long long a[maxn],b[maxn]; int n,m,k,t; struct node
{
int u,v;
} c[maxn]; int main()
{
scanf("%d",&t);
while(t--)
{
int i,u,v;
long long ans=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%d %d %d",&n,&m,&k);
for(i=0; i<k; i++)
{
scanf("%d %d",&u,&v);
a[u]++;
b[v]++;
c[i].u=u;
c[i].v=v;
}
for(i=0; i<k; i++)
{
int u=c[i].u;
int v=c[i].v;
ans+=(a[u]-1)*(b[v]-1);
}
printf("%I64d\n",ans*2);
}
return 0;
}

Count the Sheep

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

Total Submission(s): 484    Accepted Submission(s): 212

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

(bc 1002)hdu 6016 count the sheep的更多相关文章

  1. 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. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

  5. CA Loves GCD (BC#78 1002) (hdu 5656)

    CA Loves GCD  Accepts: 135  Submissions: 586  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: ...

  6. Count the Sheep 思维题

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

  7. BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5610 如果杠铃总质量是奇数直接impossible 接着就考验耐心和仔细周全的考虑了.在WA了三次后终于发 ...

  8. 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) ...

  9. HDU 4372 Count the Buildings:第一类Stirling数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看 ...

随机推荐

  1. Python进行数据分析—可视化之seaborn

    安装seaborn,可以使用 pip: pip install seaborn 也可以使用 conda: conda install seaborn 一个简单的箱线图: import numpy as ...

  2. synchronized的实现原理

    常见三种使用方法: 1)普通同步方法,锁是当前实例: 2)静态同步方法,锁是当前类的Class实例,Class数据存在永久代中,是该类的一个全局锁: 3)对于同步代码块,锁是synchronized括 ...

  3. MongoDB 分页

    使用Skip和limit可以如下做数据分页: Code: page1 = db.things.find().limit(20) page2 = db.things.find().skip(20).li ...

  4. Javascript的执行过程详细研究

    下面我们以更形象的示例来说明JavaScript代码在页面中的执行顺序.如果说,JavaScript引擎的工作机制比较深奥是因为它属于底层行为,那么JavaScript代码执行顺序就比较形象了,因为我 ...

  5. Javascript判断Chrome浏览器

    今天分享一下如何通过Javascript来判断Chrome浏览器,这里是通过userAgent判断的,检测一下userAgent返回的字符串里面是否包含“Chrome”, 具体怎么检测是通过index ...

  6. JavaScript 使用闭包保护变量 防止污染

    使用JavaScript编写插件或团队协作时,可使用闭包来解决此类以下两个问题: 1.定义过多全局变量,可能会造成全局变量命名冲突: 2.在插件内定义变量,需要保护该变量不被轻易修改: 优点:可以把局 ...

  7. ubuntu下中文输入法的配置,建议用fcitx

    Fcitx [ˈfaɪtɪks] 是一个支持扩展的输入法框架.它有自己维护的三个输入法,拼音,区位和码表:还支持其他引擎,rime 中州韵,google-pinyin,sunpinyin.Fcitx ...

  8. 11.Container With Most Water---两指针

    题目链接:https://leetcode.com/problems/container-with-most-water/description/ 题目大意:给出一串数组(a1, a2, a3, .. ...

  9. [How to] HBase的bulkload使用方法

    1.简介 将数据插入HBase表中的方法很多,我们可以通过TableOutputFormat以Mapreduce on HBase的方式将数据插入,也可以单纯的使用客户端API将数据插入.但是以上方法 ...

  10. Oracle中的dual

    简介,摘自百度百科: Oracle提供的最小的表,不论进行何种操作(不要删除记录),它都只有一条记录——'X'. 例如:执行select * from dual,里面只有一条记录:执行insert i ...