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 ...
随机推荐
- MAVEN 自定义骨架
1)根据原由的骨架先创建出一个骨架模板,例如创建一个web框架可以先通过命令 mvn archetype:generate -DarchetypeCatalog=internal 创建出一个web的 ...
- UVa 10891 - Game of Sum 动态规划,博弈 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- vue组件的使用和事件传递
子组件与父组件的事件传递具体实现如下: 子组件: <template> <section class="xftz-data-list"> <div c ...
- fabric运维
fabric中文文档:http://fabric-chs.readthedocs.io/zh_CN/chs/ 视频教程:http://study.163.com/course/courseMain.h ...
- Java基础-类和对象
类和对象 对象:对象是类的一个实例(对象不是找个女朋友),有状态和行为.例如,一条狗是一个对象,它的状态有:颜色.名字.品种:行为有:摇尾巴.叫.吃等. 类:类是一个模板,它描述一类对象的行为和状态. ...
- Docker(4):Dockerfile命令一览
1.FROM 指定基础镜像 FROM 指令用于指定其后构建新镜像所使用的基础镜像.FROM 指令必是 Dockerfile 文件中的首条命令,启动构建流程后,Docker 将会基于该镜像构建新镜像,F ...
- 数据结构~trie树(字典树)
1.概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. 我理解字典树是看了这位大佬博客.还不了解字典树的 ...
- uiautomator2 获取APP Toast内容
前言:appium必须是1.6以上的版本 环境(安装和安装都可以运行成功,我也不确定要不要这个): 1.抓到toast需要安装uiautomator2,安装npm:npm install -g cnp ...
- L308 New brain cells made throughout life
People keep making new brain cells throughout their lives (well at least until the age of 97), accor ...
- office web apps server安装部署
操作系统:windows 2012 软件下载地址: 链接:https://pan.baidu.com/s/1c3WWFs8 密码:4dcy NDP452-KB2901954-Web.exe(.Net ...