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 ...
随机推荐
- 003-RHEL7-Linux系统维护管理命令使用
系统维护管理命令: date 查看日期,设置日期 只有超级用户才能用date命令设置时间 date --help 显示时间的帮助命令 date{选项} 显示时间格式(以+开头,后面接时间格式) ...
- Win10系列:VC++绘制几何图形3
在绘制三角形之前,首先需要创建一个三角形,打开D2DBasicAnimation.h头文件,在D2DBasicAnimation类中添加如下的代码: private: //声明成员变量obje ...
- 读入excle
可以输出到csv(逗号间隔,具体搜索csv格式). csv可以在excel中直接导入. 也可以用system函数调用ssconvert从csv转xlsx:system("ssconvert ...
- webpack分离打包css和less
github仓库:https://github.com/llcMite/webpack.git 为什么要分离打包? 答:刚开始学webpack的时候就很郁闷,明明没几个文件,打包出来体积特 ...
- day04控制流程之if判断
一.控制流程之if判断 1.什么是if判断 判断一个条件如果成立则...不成立则... 2.为何要有if判断 让计算机能够像人一样具有判断能力 3.如何用if判断 ''' # 语法1: ''' if ...
- Ubuntu下如何访问Windows磁盘?
有些同学的电脑原来是Windows系统的,但为了需要,又下载了一个Ubuntu系统,变成双系统的电脑. 但是,在Ubuntu下,Windows的磁盘是打不开的,用网盘或者U盘又是很不方便,所以ljn教 ...
- 高效方便的IO库: System.IO.Pipelines
我们在编写网络程序的时候,经常会进行如下操作: 申请一个缓冲区 从数据源中读入数据至缓冲区 解析缓冲区的数据 重复第2步 表面上看来这是一个很常规而简单的操作,但实际使用过程中往往存在如下痛点: 数据 ...
- bzoj1096
题解: 斜率优化dp 代码: #include<bits/stdc++.h> typedef long long ll; ; using namespace std; int n,l,r, ...
- oo作业总结(一)
概述 经历了三次oo作业的洗礼,让我对java语言的强大以及面向对象编程有了初步的理解(当然,我是小白).本文接下来就将对自己这三次作业的代码进行分析以及分享自己的心路历程. 基础知识点考核 针对前三 ...
- HTML(五)选择器--伪类选择器
HTML代码 <body> <a href="www.baidu.com">www.baidu.com</a> </body> CS ...