链接:poj 1975

题意: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)的更多相关文章

  1. POJ 1975 Median Weight Bead

    Median Weight Bead Time Limit: 1000ms Memory Limit: 30000KB This problem will be judged on PKU. Orig ...

  2. POJ-1975 Median Weight Bead(Floyed)

    Median Weight Bead Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3162 Accepted: 1630 De ...

  3. POJ1975 Median Weight Bead floyd传递闭包

    Description There are N beads which of the same shape and size, but with different weights. N is an ...

  4. Median Weight Bead(最短路—floyed传递闭包)

    Description There are N beads which of the same shape and size, but with different weights. N is an ...

  5. 珍珠 Median Weight Bead 977

    描述 There are N beads which of the same shape and size, but with different weights. N is an odd numbe ...

  6. poj 3660 Cow Contest(传递闭包 Floyd)

    链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...

  7. Median Weight Bead_floyd

    Description There are N beads which of the same shape and size, but with different weights. N is an ...

  8. (poj 3660) Cow Contest (floyd算法+传递闭包)

    题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are par ...

  9. POJ 3275 Ranking the Cows(传递闭包)【bitset优化Floyd】+【领接表优化Floyd】

    <题目链接> 题目大意:FJ想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛$(1 ≤ N ≤ 1,000)$.FJ通过比较,已经知道了M$1 ≤ M ≤ 10,000$对相对关系.每一 ...

随机推荐

  1. ACM-简单题之Least Common Multiple——hdu1019

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  2. HDU - 1588 Gauss Fibonacci (矩阵高速幂+二分求等比数列和)

    Description Without expecting, Angel replied quickly.She says: "I'v heard that you'r a very cle ...

  3. 代码重构 & 代码中的坏味道

    1.重构 1.1 为什么要重构 1.1.1 改进程序设计 程序员为了快速完成任务,在没有完全理解整体架构之前就开始写代码, 导致程序逐渐失去自己的结构.重构则帮助重新组织代码,重新清晰的体现 程序结构 ...

  4. Asp.Net2.0下C#环境 Login控件实现用户登录

    原文:Asp.Net2.0下C#环境 Login控件实现用户登录 一.前台显示效果 二.前台代码             <asp:Login ID="Login1" run ...

  5. java该HashTable,HashMap和HashSet

    同一时候我们也对HashSet和HashMap的核心方法hashcode进行了具体解释,见<探索equals()和hashCode()方法>. 万事俱备,那么以下我们就对基于hash算法的 ...

  6. Windows Phone开发(39):漫谈关键帧动画上篇

    原文:Windows Phone开发(39):漫谈关键帧动画上篇 尽管前面介绍的几种动画会让觉得很好玩了,但是,不知道你是否发现,在前面说到的一系列XXXAnimation中,都有一个共同点,那就是仅 ...

  7. BZOJ 1269 文本编辑器 Splay

    题目大意:维护一个文本编辑器,支持下列操作: 1.将光标移动到某一位置 2.在光标后插入一段字符串 3.删除光标后的一段字符 4.翻转光标后的一段字符 5.输出光标后的一个字符 6.光标-- 7.光标 ...

  8. MVC模块化架构

    全面解析ASP.NET MVC模块化架构方案 什么叫架构?揭开架构神秘的面纱,无非就是:分层+模块化.任意复杂的架构,你也会发现架构师也就做了这两件事. 本文将会全面的介绍我们团队在模块化设计方面取得 ...

  9. Visibility属性实现自动隐藏功能

    //使用一个Button,鼠标移入listView显示,移出隐藏 private void button2_MouseEnter(object sender, System.Windows.Input ...

  10. SAP ABAP计划 SY-REPID与SY-CPROG差异

    首先,它的两个解释   sy-repid is the name of the current program.  "当前程序的程序名                             ...