HDU 6016 Count the Sheep
Count the Sheep
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 686 Accepted Submission(s): 295
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 <= 100000
there should be 1 integer in the line which represents the number of the counting way of 4-sheep-sequence before luras's sleep.
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
8
0
2找规律的题目先算出来开端是男孩是情况ans,最后的结果是ans*2四个关系 男-女-男-女就像一颗只有四层的树,最后一层叶子节点的个数就是答案#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector> using namespace std;
typedef long long int LL;
const int maxn=1e5;
int n,m,k;
vector<int> a[maxn+5];
vector<int> b[maxn+5];
int aa[maxn+5];
int bb[maxn+5];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
int x,y;
for(int i=1;i<=n;i++)
a[i].clear();
for(int i=1;i<=m;i++)
b[i].clear();
memset(aa,0,sizeof(aa));
memset(bb,0,sizeof(bb));
for(int i=1;i<=k;i++)
{
scanf("%d%d",&x,&y);
a[x].push_back(y);
b[y].push_back(x);
aa[x]++;
bb[y]++;
}
LL ans=0;
for(int i=1;i<=n;i++)
{
LL res=0;
for(int j=0;j<aa[i];j++)
{
res+=(bb[a[i][j]]-1);
}
ans+=res*(aa[i]-1);
}
printf("%lld\n",ans*2);
}
return 0;
}
HDU 6016 Count the Sheep的更多相关文章
- (bc 1002)hdu 6016 count the sheep
Count the Sheep Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU - 6016 Count the Sheep 二分图+思维
Count the Sheep 题意: 问题描述 开学翘课固然快乐,然而也有让呃喵抓狂的事,那当然就是考试了!这可急坏了既要翘课又想要打BC还要准备考试的呃喵. 呃喵为了准备考试没有时间刷题,想打BC ...
- hdu 6016 Count the Sheep(思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6016 题意:给定男羊和女羊的朋友关系,即给定一个图,问从任意一只羊开始连续数四只不相同的羊的方法数. ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Count the Sheep 思维题
Altough Skipping the class is happy, the new term still can drive luras anxious which is of course b ...
- HDU 5901 Count primes 论文题
Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...
- hdu 3336 Count the string -KMP&dp
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- HDU 6470 Count 【矩阵快速幂】(广东工业大学第十四届程序设计竞赛 )
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6470 Count Time Limit: 6000/3000 MS (Java/Others) ...
- HDU 4372 Count the Buildings
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- javascript -- 将数组转换为字符串:join()
join(separator) 方法用于把数组中的所有元素放入一个字符串.元素是通过指定的分隔符进行分隔的. separator:可选,指定要使用的分隔符.如果省略该参数,则默认使用逗号作为分隔符 v ...
- 关于对afx_msg的解释-----来源百度百科
1AFX前缀 Afx前缀是微软MFC一个小组的名称简写,并没有别的意义. MFC的很多代码,包括全局函数名.宏.头文件名都使用了"Afx". Afx*.h是一组MFC的核心头文件, ...
- SharePoint Error occurred in deployment step 'Recycle IIS Application Pool': 0x80070005:拒绝访问
错误出现的前提:多个用户在一台机器上做开发,使用非系统管理员账号时会出现,因为一般创建网站集时指定管理员为系统管理员: 使用 Visual Studio 2010 部署时报错:Error occurr ...
- json格式的javascript对象用法分析
格式: objectName = { property1:value1, property2:value2, …, propertyN:valueN } property是对象的属性 ,val ...
- mysql表无权限访问
当网页出现以上问题时的解决方法: 今天在两台服务器间转移网站,最后把域名解释设置好后等待...然后CMD查看DNS解释情况..解释成功-输入网址-却出现如上信息,首先用#ls -l查看mysql下的v ...
- brew 的 调度工具DBGPRINTF 和 c语言的 printf
在官方的文档中是这样备注DBGPRINTF Prototype void dbgprintf(const char *pszFormat,...); Description This function ...
- float类型如何转换为string类型
在一些很大的float类型的地方会用科学记数法表示,这个时候如果想完整记录下来,还是得转字符串,这里书写一个float类型转string类型的方法 <?php function float_to ...
- python2.0_s12_day12_css样式详解
CSScss是英文Cascading Style Sheets的缩写,称为层叠样式表,用于对页面进行美化. CSS 存放方式有三种: 一种写法:在<body></body>内部 ...
- Qt选择文件对话框-中文路径-转std::string
#include <QFileDialog>#pragma execution_character_set("utf-8") QString path = QFileD ...
- Qt监控excel
配置文件setup.ini内容 [General] ExcelFilePath=D:/项目资料/GSC-西门子开关/GSCOPC.xlsx GameIp=192.168.1.152 GamePort= ...