poj3275
比较笨啊,一直在想,到底问几次绝对能知道所有的关系呢?
后来看了题解才知道,问一次最少确定一对关系…………
这就好办le,n头牛有C(2,n)个关系
现在给出m条边,以确定的关系有多少呢?直接dfs啊……
……O(nm)
type link=^node;
node=record
po:longint;
next:link;
end;
var w:array[..] of link;
sum:array[..] of longint;
v:array[..] of boolean;
n,i,m,ans,x,y:longint; procedure add(x,y:longint);
var p:link;
begin
new(p);
p^.next:=w[x];
p^.po:=y;
w[x]:=p;
end; procedure dfs(i:longint);
var p:link;
y:longint;
begin
p:=w[i];
v[i]:=true;
sum[i]:=;
while p<>nil do
begin
y:=p^.po;
if not v[y] then
begin
dfs(y);
sum[i]:=sum[i]+sum[y];
end;
p:=p^.next;
end;
end; begin
readln(n,m);
for i:= to m do
begin
readln(x,y);
add(x,y);
end;
for i:= to n do
begin
fillchar(v,sizeof(v),false);
dfs(i);
ans:=ans+sum[i]-;
end;
writeln(n*(n-) div -ans);
end.
poj3275的更多相关文章
- POJ3275 Ranking the Cows floyd的bitset优化
POJ3275 Ranking the Cows #include <iostream> #include <cstdio> #include <bitset> u ...
- 离散数学-传递闭包(POJ3275)
就是n的元素给定m个关系求他们之间的关系. eg. ∵a>b and b>c ∴a>c emmmm 若要知道n个元素的绝对关系,则需知道C(n,2)个关系. 例题:POJ3275 ...
- POJ3275:Ranking the Cows(Bitset加速floyd求闭包传递)
Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ woul ...
- POJ-3275:Ranking the Cows(Floyd、bitset)
Ranking the Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3301 Accepted: 1511 ...
- 【Bitset】重识
---------------------------------------------------------------------------- 一题题目: 一题题解: 这个题目哪来入门再好不 ...
- USACO 2007 “March Gold” Ranking the Cows
题目链接:https://www.luogu.org/problemnew/show/P2881 题目链接:https://vjudge.net/problem/POJ-3275 题目大意 给定标号为 ...
- poj 3275 "Ranking the Cows"(DFS or Floyd+bitset<>)
传送门 题意: 农场主 FJ 有 n 头奶牛,现在给你 m 对关系(x,y)表示奶牛x的产奶速率高于奶牛y: FJ 想按照奶牛的产奶速率由高到低排列这些奶牛,但是这 m 对关系可能不能精确确定这 n ...
随机推荐
- Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll
Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...
- Spark Streaming揭秘 Day27 Job产生机制
Spark Streaming揭秘 Day27 Job产生机制 今天主要讨论一个问题,就是除了DStream action以外,还有什么地方可以产生Job,这会有助于了解Spark Streaming ...
- Spark Streaming揭秘 Day3-运行基石(JobScheduler)大揭秘
Spark Streaming揭秘 Day3 运行基石(JobScheduler)大揭秘 引子 作为一个非常强大框架,Spark Streaming兼具了流处理和批处理的特点.还记得第一天的谜团么,众 ...
- java之StringBuffer
StringBuffer就是字符串缓冲区,用于存储数据的容器. 特点:长度可变,可存储不同类型的数据,最终转化成字符串使用,可以对字符串修改 功能: 添加:append(value), insert( ...
- Linux 目录操作和4中文件拷贝效率测试
/*1.用户输入任意目录名称,显示该目录下的文件列表信息,包括文件类型,文件权限,文件大小,文件名称2.拷贝用户输入的文件到当前目录下3.第二点功能,使用4种方式完成,并比较说明效率*/ /* str ...
- psutil--跨平台的进程管理
原文地址:http://www.jianshu.com/p/64e265f663f6 Python处理Windows进程 psutil(Python system and process utilit ...
- mybatis + postgresql 遇到的问题
org.postgresql.util.PSQLException: ERROR: relation "circlefence" does not exist 这个问题是数据库表 ...
- [译] ASP.NET 生命周期 – ASP.NET 请求生命周期(四)
不使用特殊方法来处理请求生命周期事件 HttpApplication 类是全局应用类的基类,定义了可以直接使用的一般 C# 事件.那么使用标准 C# 事件还是特殊方法那就是个人偏好的问题了,如果喜欢, ...
- DNF技能贴图的研究
一直在猜想DNF的技能贴图怎么贴的,靠在游戏里慢慢移动确定技能的偏移太费时间了.前段发现了“可视坐标生成”这软件,针对DNF改衣服,装备款式的小工具,就自己写了个类似的. 从图上看,技能的域中心点和人 ...
- 1025: [SCOI2009]游戏 - BZOJ
Description windy学会了一种游戏.对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应.最开始windy把数字按顺序1,2,3,……,N写一排在纸上.然后再在这一排下面写上它们对 ...