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 ...
随机推荐
- VMware workstation 14 Pro下载、安装及激活码
虚拟机安装 1.百度搜索VMware应用程序 2.功能介绍 3.下载完成 4.开始安装 双击应用程序开始安装 5.点击“下一步” 6.勾选“我接受” 选择“下一步” 7.安装文件的选择:1.默认安装路 ...
- javascript 跑马灯
1.看了写跑马灯的教程案例,隔了段时间自己写了一个简单的跑马灯.将过程中遇到的问题特此记录下来 代码如下: <!DOCTYPE html> <html> <head> ...
- oo作业总结报告2
第五次作业 多线程电梯 多线程同步和控制的设计策略 明确类和对象,以及是否区分对象实例.具体类可以从类图中看出: 明确线程的类型和数量.输入作为一个线程,调度作为一个线程,三个电梯独立工作,互不影响, ...
- 经典DFS问题实践
八皇后问题: //八皇后问题 经典的DFS问题实践 #include<iostream> #include<cmath> #include<algorithm> # ...
- mysql 数据迁移
最近线上系统新挂了一次磁盘,需要将系统磁盘下的 mysql 数据目录迁移到 数据盘上. 经过一番考察,mysql在安装时,使用了预编译的二进制tar.gz包.共有两处配置了 datadir属性 /et ...
- vue-1-模板语法
文本 <span>Message: {{ msg }}</span><span v-once>这个将不会改变: {{ msg }}</span> 原始 ...
- Centos常用快捷键
终端快捷键 tab=补全 ctrl+a=开始位置 ctrl+e=最后位置 ctrl+k=删除此处至末尾所有内容 ctrl+u=删除此处至开始所有内容 ctrl+d=删除当前字母 ctrl+w=删除此 ...
- Cracking The Coding Interview 9.0
#include <iostream> #include <vector> using namespace std; void mswap(int &a, int &a ...
- datatabale 服务器分页
转载:http://blog.csdn.net/angelvyvyan/article/details/51783272$(document).ready( function() { $('#tabl ...
- 用户登录页面——jdbc
登录页面程序login.jsp <%@ page language="java" import="java.util.*" pageEncoding=&q ...