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.

InputThe 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 <= 100000OutputAs 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 这道题让我想到了二分图,离散刚学的,就是两边元素之间有边连接,各边元素之间无连接,要找出4个元素满足,A-B,B-C,C-D,注意一下,ABCD满足的话,DCBA也满足,可以考虑分析每一对男女,看看男的有几个女朋友,女的有几个男朋友,各自减一相乘就好了,有点像排列组合,最后再乘2,就ok。 代码:
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std; #define init(a) memset(a,0,sizeof(a))
struct rela
{
int x,y;
}re[];
int main()
{
int t,n,m,k,x,y;
long long ans;
int b[],g[];
cin>>t;
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
init(b);
init(g);
ans=;
for(int i=;i<k;i++)
{
scanf("%d%d",&x,&y);
b[x]++;
g[y]++;
re[i].x=x,re[i].y=y;
}
for(int i=;i<k;i++)
{
ans+=(b[re[i].x]-)*(g[re[i].y]-);
}
cout<<ans*<<endl;
}
}

Count the Sheep 思维题的更多相关文章

  1. Codeforces 1188B - Count Pairs(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...

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

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

  3. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

  4. (bc 1002)hdu 6016 count the sheep

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

  5. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  6. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  7. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  8. 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)

    思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...

  9. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. mex

    edit(fullfile(prefdir, 'mexopts.bat')) http://www.mathworks.cn/support/solutions/en/data/1-8FJXQE/in ...

  2. linux初始化宏__init, __exit

    我们在内核中经常遇到初始化函数是这样定义的:static int __init init_func(); ,与普通函数相比,定义中多了__init.那么,__init是什么意思呢?还有与其匹配的__e ...

  3. Linux下IP的存储位置

    在linux下,配置多个IP的话,通常是eth0... eth0. ..eth0.x等等, 那么如果要配置大量的IP呢,这么配置也是可以的,但是繁琐,虽说这种情况很少. 对于添加大量IP,有一定规定的 ...

  4. maven scope和项目发布需要注意的地方

    Maven Scope的使用: http://www.cnblogs.com/wangyonghao/p/5976055.html servlet-api和jsp-api等jar包,一般由servle ...

  5. ios 设置本地化显示的app名称

    内容的本地化这里不做介绍! 名称的本地化: 1.新建一个 Strings File文件,命名为InfoPlist,注意这里一定要命名为InfoPlist! 2.设置本地化信息:选择需要的语言! 3.填 ...

  6. 深入理解java虚拟机---java虚拟机的发展史(四)

    1.java虚拟机 A:java虚拟机有很多个版本,但是我们经常使用的是sun公司的HotSpot,可以通过以下命令获取java虚拟机版本 B:JAVA虚拟机分类: 1.Sun Class VM 2. ...

  7. 4.3 C++虚成员函数表vtable

    参考:http://www.weixueyuan.net/view/6372.html 总结: 在C++中通过虚成员函数表vtable实现多态,虚函数表中存储的是类中虚函数的入口地址. 使用多态会降低 ...

  8. 干货分享!DevExpress v17.1最新版帮助文档下载大全

    DevExpress v17.1.5帮助文档下载列表大全来啦!包含.NET.VCL.HTML/JS系列所有帮助文档,提供CHM和PDF两个版本.除已停止更新的Silverlight.Windows 8 ...

  9. 一、TCP扫描技术

    一.TCP扫描技术 常用的端口扫描技术有很多种,如 TCP connect() 扫描 .TCP SYN 扫描.TCP FIN 扫描 等,网络上也有很多文章专门介绍,比如 :http://www.ant ...

  10. jdk,jre和jvm

    JDK(Java Development Kit)是针对Java开发员的产品,是整个Java的核心,包括了Java运行环境JRE.Java工具和Java基础类库 JRE是Java Runtime En ...