Count the Sheep 思维题
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.
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 思维题的更多相关文章
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
- HDU - 6016 Count the Sheep 二分图+思维
Count the Sheep 题意: 问题描述 开学翘课固然快乐,然而也有让呃喵抓狂的事,那当然就是考试了!这可急坏了既要翘课又想要打BC还要准备考试的呃喵. 呃喵为了准备考试没有时间刷题,想打BC ...
- 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 ...
- (bc 1002)hdu 6016 count the sheep
Count the Sheep Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- 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 ...
随机推荐
- learning ddr mode register MR2
- Linux command stty
Linux command stty reference: https://blog.csdn.net/lqxandroid2012/article/details/78929506 [Purpose ...
- 利用VisualVm和JMX远程监控Java进程
自Java 6开始,Java程序启动时都会在JVM内部启动一个JMX agent,JMX agent会启动一个MBean server组件,把MBeans(Java平台标准的MBean + 你自己创建 ...
- OO Summary Ⅲ
规格化设计的发展历史 (这一部分并没有找到答案,于是参考了好黄和温莎莎的blogs) 1950年代,第一次分离,主程序和子程序的分离程序结构模型是树状模型,子程序可先于主程序编写.通过使用库函数来简化 ...
- 阿里云服务器创建swap分区
阿里云服务器使用了4核8G内存配置,但最近由于jenkins构建时执行gradle打包安卓应用,导致即时的内存严重不足,线上应用长时间无法访问. 执行free命令才发现,swap分区一直是没有创建的. ...
- MySQL 占用cpu 100%
目前的线上数据库,分为主从两个库,从库用来做比较耗时的数据统计分析. 今天top了一下从库服务器,发现mysqld 在很长一段时间都占用105% cpu,一开始以为是从库在处理主库的binlog. 两 ...
- weblogic连接池过小导致TPS呈周期性跳坑现象
利用晚上时间跑个12小时稳定性,第二天发现TPS曲线图成了这个样子. 排查步骤: 1.观察TPS图发现,几乎每两个小时TPS掉一次坑,是周期性的,而且TPS有掉到0的现象.LR上也有失败的交易,猜想是 ...
- DevExpress WPF v18.2新版亮点(一)
买 DevExpress Universal Subscription 免费赠 万元汉化资源包1套! 限量15套!先到先得,送完即止!立即抢购>> 行业领先的.NET界面控件2018年第 ...
- Positioning
boxPostion.html <html><head> <title>Box Position</title><meta charset=& ...
- linux一些命令的介绍
http://www.runoob.com/linux/linux-command-manual.html 寻找文档操作命令wc -l时,发现一个好的介绍linux操作命令的网站.