链接: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. AppWidget应用(二)---PendingIntent 之 getActivity

    通过AppWidget应用(一)的介绍,我们已经知道如何创建一个在主界面上显示一个appWidget窗口,但这并不是我们的目的,我们需要做到程序与用户之间进行交互:下面来介绍下如何通过appWidge ...

  2. Mac下配置Cocos2d-x3.1环境

    一.前期准备 1.ADT:百度下就OK 2.NDK:百度下就OK 3.ANT: http://124.254.47.39/download/55152992/78533365/4/zip/57/132 ...

  3. UIView详解2

    第三.Configuring the Event-Related Behavior 1.  userInteractionEnabled  property A Boolean value that ...

  4. [欧拉] poj 2513 Colored Sticks

    主题链接: http://poj.org/problem? id=2513 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Tota ...

  5. 存读Blob Oracle

  6. Context Switch and System Call

    How many Context Switches is “normal”? This depends very much on the type of application you run. If ...

  7. poj1236 有向图加边变成强连通图

    给我们一个有向图,有两个问题 1.最少要给多少个点发消息,才能使得所有的点都收到消息(消息可以随边传递) 2.最少需要多少条边才能使得图变成强连通图 对于一个强连通分量,可以当做一个点来考虑,所以我们 ...

  8. listary文件查找程序下载和使用

    资源:PHP开发学习门户网站 地址:http://bbs.phpthinking.com/forum.php?mod=viewthread&tid=173 Listary 是一款有用的国产Wi ...

  9. js调用百度地图接口

    原文:js调用百度地图接口 这是前几天公司做的新项目,上面需要用到地图的数据.第一次做这类型的东西没啥思路,咱们经理说,这东西简单,截个图存文件夹里调整好尺寸,数据库里存上图片的地址动态调用就行了.心 ...

  10. 重新想象 Windows 8 Store Apps (15) - 控件 UI: 字体继承, Style, ControlTemplate, SystemResource, VisualState, VisualStateManager

    原文:重新想象 Windows 8 Store Apps (15) - 控件 UI: 字体继承, Style, ControlTemplate, SystemResource, VisualState ...