POJ 1975 Median Weight Bead
Median Weight Bead
This problem will be judged on PKU. Original ID: 1975
64-bit integer IO format: %lld Java class name: Main
A scale is given to compare the weights of beads. We can determine which one is heavier than the other between two beads. As the result, we now know that some beads are heavier than others. We are going to remove some beads which cannot have the medium weight.
For example, the following results show which bead is heavier after M comparisons where M=4 and N=5.
1. Bead 2 is heavier than Bead 1.
2. Bead 4 is heavier than Bead 3.
3. Bead 5 is heavier than Bead 1.
4. Bead 4 is heavier than Bead 2.
From the above results, though we cannot determine exactly which is the median bead, we know that Bead 1 and Bead 4 can never have the median weight: Beads 2, 4, 5 are heavier than Bead 1, and Beads 1, 2, 3 are lighter than Bead 4. Therefore, we can remove these two beads.
Write a program to count the number of beads which cannot have the median weight.
Input
The first line of input data contains an integer N (1 <= N <= 99) denoting the number of beads, and M denoting the number of pairs of beads compared. In each of the next M lines, two numbers are given where the first bead is heavier than the second bead.
Output
Sample Input
1
5 4
2 1
4 3
5 1
4 2
Sample Output
2
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
bool g[maxn][maxn];
int n,m;
void Floyd() {
for(int k = ; k <= n; ++k) {
for(int i = ; i <= n; ++i) {
if(g[i][k]) {
for(int j = ; j <= n; ++j) {
if(!g[i][j]) g[i][j] = g[i][k]&&g[k][j];
}
}
}
}
}
int main() {
int u,v,x,y,T;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
memset(g,false,sizeof(g));
for(int i = ; i < m; ++i){
scanf("%d %d",&u,&v);
g[u][v] = true;
}
Floyd();
int ans = ;
for(int i = ; i <= n; ++i){
x = y = ;
for(int j = ; j <= n; ++j){
if(g[i][j]) x++;
if(g[j][i]) y++;
}
if(x > (n-)>> || y > (n-)>>) ans++;
}
cout<<ans<<endl;
}
return ;
}
POJ 1975 Median Weight Bead的更多相关文章
- poj 1975 Median Weight Bead(传递闭包 Floyd)
链接:poj 1975 题意:n个珠子,给定它们之间的重量关系.按重量排序.求确定肯定不排在中间的珠子的个数 分析:由于n为奇数.中间为(n+1)/2,对于某个珠子.若有至少有(n+1)/2个珠子比它 ...
- 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 977
描述 There are N beads which of the same shape and size, but with different weights. N is an odd numbe ...
- 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_floyd
Description There are N beads which of the same shape and size, but with different weights. N is an ...
- poj 3579 Median (二分搜索之查找第k大的值)
Description Given N numbers, X1, X2, ... , XN, let us calculate the difference of every pair of numb ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- POJ 3579 Median(二分答案)
Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11599 Accepted: 4112 Description G ...
随机推荐
- 关于Number的属性和方法你知晓几分?速来围观!
1.Number.isFinite() 方法用来检测传入的参数是否是一个有穷数(finite number)返回值为布尔值. 和全局的 isFinite() 函数相比,这个方法不会强制将一个非数值的参 ...
- 禁止浏览器缓存input值
如果不想让浏览器缓存input的值,有2种方法: 方法一: 在不想使用缓存的input中添加 autocomplete="off"; <input type="te ...
- jQuery 事件流的概念
jQuery 事件流的概念 什么是事件流 DOM事件流 1. 事件捕获阶段; 2.处于目标阶段; 3.事件冒泡阶段; <!DOCTYPE html> <html lang=&quo ...
- bitset优化背包
题目:https://agc020.contest.atcoder.jp/tasks/agc020_c 回忆下一题,是零一背包,主要的做法就是凑出最接近sum/2的价值,然后发现现在的背包的容量是20 ...
- 利用CORS解决前后端分离的跨域资源问题
CORS 即CrossOrigin Resources Sharing-跨域资源共享,它定义了一种浏览器和服务器交互的方式来确定是否允许跨域请求.它是一个妥协,有更大的灵活性,但比起简单地允许所有这些 ...
- Bate版总结会议2
本次会议主要是针对我们在冲刺阶段出现的问题进行的讨论.再有就是以后在开发中应该改进的地方. 问题一: 工作任务不能拖:因为任务一拖就很可能无法再规定的时间内完成,如果我们可以分配好任务就去做的话,我们 ...
- 题目1437:To Fill or Not to Fill(贪心算法)
题目描写叙述: With highways available, driving a car from Hangzhou to any other city is easy. But since th ...
- hdu5033 Building 单调队列
// hdu5033 Building 单调队列 // // 题目大意: // // n栋大楼,有一个高度h和位置x.如今有一个人高度为0,有q个询问 // 每一个询问有一个位置x,求在位置x能看到天 ...
- zzulioj--1600--直线与圆(简单数学几何)
1600: 直线与圆 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 360 Solved: 73 SubmitStatusWeb Board ...
- javascript系列-class3.循环语句
欢迎加入前端交流群来py: 转载请标明出处! while循环 while(循环终止条件){ } 案例 输出0~100个数字 1 . 3 . 5 不输出 输出一百数字 ...