首页 > 其他分享 >ZOJ4124 Median

ZOJ4124 Median

时间:2023-02-04 11:03:12浏览次数:61  
标签:ZOJ4124 int graph scanf Median 110 cnt1 ans


题目链接:​​点击这里​

n个数m组大小关系,求第i个数是否能作为第(n+1)2大的数。

拓扑判环,然后两次dfs

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

bool graph[110][110];
void floyd(int n)
{
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (graph[i][k] && graph[k][j])
graph[i][j] = true;
}


int main()
{
int t;
scanf("%d", &t);

while (t--)
{
memset(graph, 0, sizeof(graph));
int n, m;
scanf("%d %d", &n, &m);

while (m--)
{
int x, y;
scanf("%d %d", &x, &y);
graph[x][y] = true;
}

floyd(n);

bool flg = true;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (graph[i][j] == graph[j][i] && graph[i][j] == 1)
{
flg = false;
}
}
}
int ans[110] = { 0 };
if (flg)
for (int i = 1; i <= n; i++)
{
int cnt1 = 0;
int cnt2 = 0;
for (int j = 1; j <= n; j++)
{
if (i == j)
continue;
if (graph[i][j])
cnt1++;
if (graph[j][i])
cnt2++;
}

if (cnt1 <= n / 2 && cnt2 <= n / 2)
{
ans[i] = 1;
}
}
for (int i = 1; i <= n; i++)
printf("%d", ans[i]);
printf("\n");
}
;;;
return 0;
}

 

标签:ZOJ4124,int,graph,scanf,Median,110,cnt1,ans
From: https://blog.51cto.com/u_15952369/6036929

相关文章

  • Codeforces1201 B Maximum Median (二分)
    Description:Youaregivenanarray aa of nn integers,where nn isodd.Youcanmakethefollowingoperationwithit:Chooseoneoftheelementsofthearray......
  • abc236 E - Average and Median
    题意:在给定数组中选数,要求任意相邻的两数至少选一个。问选出来的数的最大平均数和最大中位数\(n\le1e5,1\lea_i\le1e9\)思路:平均数、中位数的典中典二分+转化this......
  • CF1761F Anti-median (Easy Version)
    称一个排列是好的,当且仅当对于所有\(m\)都满足所有长度为\(2m+1\)的子串的中位数不在第\(m+1\)个。给定一个一些数被替换成\(-1\)的排列\(p\),你需要统计所有可能......
  • AGC006D Median Pyramid Hard
    ​​\(AGC006D\)\(Median\)\(Pyramid\)\(Hard\)​​一、题目描述二、题目解析这道例题看到时毫无头绪,因为课程是二分,所以往二分的方向想,猜到是二分枚举最上面的那个数是......
  • Median
    Medianhttp://poj.org/problem?id=3579 思路参考:https://www.cnblogs.com/sky-stars/p/11317030.html lower_boundhttp://c.biancheng.net/view/7521.html ......
  • LeetCode:295. Find Median from Data Stream
    LeetCode:295.FindMedianfromDataStream题目描述Medianisthemiddlevalueinanorderedintegerlist.Ifthesizeofthelistiseven,thereisnomiddleval......
  • Count Subarrays With Median K
    CountSubarraysWithMedianKYouaregivenanarray nums ofsize$n$ consistingofdistinctintegersfrom$1$to$n$andapositiveinteger$k$.Returnthe......
  • 4. Median of Two Sorted Arrays
    Giventwosortedarrays nums1 and nums2 ofsize m and n respectively,return themedian ofthetwosortedarrays.Theoverallruntimecomplexitysho......
  • PAT_甲级_1029 Median (25分) (C++)【求中位数/递增序列合并】
    目录​​1,题目描述​​​​题目大意​​​​2,思路​​​​3,代码​​1,题目描述SampleInput:4111213145910151617 SampleOutput:13题目大意求两递增序列的中位数(......
  • 【数编】【题记】Running Median 对顶堆、链表
    title:POJ3784RunningMediandate:2022-10-14周五tags:对顶堆双向链表数据结构编程实验线性表题记一题多解mindmap-plugin:basicPOJ3784RunningMed......