链接: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. jquery实现上传图片预览(需要浏览器支持html5)

    jquery实现上传图片预览(需要浏览器支持html5) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  2. java文件创建、删除、读取、写入操作大全

    一.获得控制台用户输入的信息 public String getInputMessage() throws IOException...{ System.out.println("请输入您的 ...

  3. Audio Offload

    Audio Offload 音频分载,是系统将音频分载到声卡硬件进行分载处理的功能.从Windows 8开始,音频的硬件加速和分载处理又回来了.为什么说又回来了呢? 因为声卡自创通公司发明开始,相当长 ...

  4. css中padding中样式的顺序含义

    4种可能的情况.举例说明: padding:10px; 四个内边距都是10px padding:5px 10px; 上下5px 左右10px padding:5px 10px 15px; 上5px 右 ...

  5. hdu 5187 高速幂高速乘法

    http://acm.hdu.edu.cn/showproblem.php?pid=5187 Problem Description As one of the most powerful brush ...

  6. 全栈project师的毁与誉

    全栈(Full Stack)project师.也能够叫全端project师,不管是前端知识,还是后端架构你都要了解.甚至有些调皮的程序猿这样理解全栈project师:全栈project师 = 屌丝战斗 ...

  7. Android实现限制EditText输入文字的数量

    一: 声明控件.          TextView hasnumTV;         TextView hasnum;// 用来显示剩余字数         int num = 50;// 限制的 ...

  8. UltraEdit-32 温馨提示:右协会,取消 bak文件

    1.最近安装UltraEdit-32 无权协会,能够 高级 ->组态 ->文件关联 在 检查 继承到资源管理器 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...

  9. JQuery打印

    jquery.jqprint-0.3.js JQuery提供的局部打印功能: <input type="button" value="打印" onclic ...

  10. Hadoop认知--在不同的阶段

    入门阶段 出于兴趣,及工作中的简单有用,大约经过1个月的时间,完毕了对Hadoop的基本认知. 在这个月中我干了例如以下几件事 1.大体看了<Hadoop权威指南>.把里面的代码手工码了一 ...