poj 1975 Median Weight Bead(传递闭包 Floyd)
题意:n个珠子,给定它们之间的重量关系。按重量排序。求确定肯定不排在中间的珠子的个数
分析:由于n为奇数。中间为(n+1)/2,对于某个珠子。若有至少有(n+1)/2个珠子比它重或轻,则它肯定不排在中间
能够将能不能确定的权值初始化为0,能确定重量关系的权值设为1
#include<stdio.h>
#include<string.h>
int a[110][110];
int main()
{
int T,n,m,i,j,k,d,x,sum;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
memset(a,0,sizeof(a));
while(m--){
scanf("%d%d",&i,&j);
a[i][j]=1;
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][k]&&a[k][j]) //当i比k重,k比j重,则i比j重
a[i][j]=1;
sum=0;
for(i=1;i<=n;i++){
d=x=0;
for(j=1;j<=n;j++){
if(a[i][j])
d++;
else if(a[j][i])
x++;
}
if(d>=(n+1)/2||x>=(n+1)/2)
sum++;
}
printf("%d\n",sum);
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
poj 1975 Median Weight Bead(传递闭包 Floyd)的更多相关文章
- POJ 1975 Median Weight Bead
Median Weight Bead Time Limit: 1000ms Memory Limit: 30000KB This problem will be judged on PKU. Orig ...
- POJ-1975 Median Weight Bead(Floyed)
Median Weight Bead Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3162 Accepted: 1630 De ...
- POJ1975 Median Weight Bead floyd传递闭包
Description There are N beads which of the same shape and size, but with different weights. N is an ...
- Median Weight Bead(最短路—floyed传递闭包)
Description There are N beads which of the same shape and size, but with different weights. N is an ...
- 珍珠 Median Weight Bead 977
描述 There are N beads which of the same shape and size, but with different weights. N is an odd numbe ...
- poj 3660 Cow Contest(传递闭包 Floyd)
链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...
- Median Weight Bead_floyd
Description There are N beads which of the same shape and size, but with different weights. N is an ...
- (poj 3660) Cow Contest (floyd算法+传递闭包)
题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are par ...
- POJ 3275 Ranking the Cows(传递闭包)【bitset优化Floyd】+【领接表优化Floyd】
<题目链接> 题目大意:FJ想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛$(1 ≤ N ≤ 1,000)$.FJ通过比较,已经知道了M$1 ≤ M ≤ 10,000$对相对关系.每一 ...
随机推荐
- 158个JAVA免豆精品资料汇总
附件完整版下载地址: http://down.51cto.com/data/431561 附件部分预览~ java中国移动收费系统[源代码] http://down.51cto.com/data/70 ...
- Using OpenCV Java with Eclipse(转)
转自:http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html Using Open ...
- js实现的侧边栏展开收缩效果
原文地址:http://www.softwhy.com/forum.php?mod=viewthread&tid=12246 <!DOCTYPE html> <html> ...
- qt的资源替换搜索QDir具体解释
QDir对跨平台的文件夹操作提供了非常多的便利,为了更加方便的提供全局资源的查找,QDir提供了搜索路径替换功能,攻克了资源搜索不便的问题,也能提高文件查找的效率. QDir通过已知的路径前缀去搜索并 ...
- POJ 2536 Gopher II(二分图的最大匹配)
题目链接:http://poj.org/problem?id=2536 题意:已知有n仅仅老鼠的坐标,m个洞的坐标,老鼠的移动速度为V,S秒以后有一仅仅老鹰要吃老鼠,问有多少个老鼠被吃. 非常明晰,二 ...
- java日历程序版本
//MainFrame.java package com.huowolf.myCalender; import java.awt.BorderLayout; import java.awt.Color ...
- Deploy 11.2.0.3 RAC+DG on Windows 2008 R2 Step by Step
环境规划: 节点1: tc1 192.168.56.101 内存:2G 节点2: tc2 192.168.56.102 内存:2G 物理备库:tcdg192.168.56.108内存:1.5G 操作系 ...
- 【Unity Shaders】使用Unity Render Textures实现画面特效——画面特效中的亮度、饱和度和对照度
本系列主要參考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同一时候会加上一点个人理解或拓展. 这里是本书全部的插图. 这里是本书所需的代码 ...
- Date()创建日期
哎. .这些人变得懒惰个月...经过以上撰写博客的工作 上周五测试报告的问题.上述日期的计算是有问题.两个日期之间的差异原创1天,然而,系统将计算的差31天. (就在那一天2014年10月31日本 星 ...
- USACO comehome Dijkstra
USER: Kevin Samuel [kevin_s1] TASK: comehome LANG: C++ Compiling... Compile: OK Executing... Test 1: ...