当前位置: 首页 > news >正文

上海营销平台网站建设网络营销图片

上海营销平台网站建设,网络营销图片,wordpress 调用评论数量,网页设计视频教程-响应式手机网站制作题目大意 给你一个n*m的矩阵,其中-1代表可以填入任意非负数 求是否能够通过调换列的顺序,使得每一行变为非递减数列 如果可以,输出调换列的顺序 否则输出-1 思路 可以把每一列看成一个点,那么其实就是把m个点进行排序&#xff…

在这里插入图片描述
在这里插入图片描述

题目大意

给你一个n*m的矩阵,其中-1代表可以填入任意非负数
求是否能够通过调换列的顺序,使得每一行变为非递减数列
如果可以,输出调换列的顺序
否则输出-1

思路

可以把每一列看成一个点,那么其实就是把m个点进行排序,使得其满足题目的要求

可以想到使用拓扑排序,拓扑排序的本质是处理有向无环图中的偏序关系,即找到一个线性顺序,使得所有边的约束都被满足,在本题中:每个列是图中的一个节点。每一行的非 -1 元素会生成一系列约束(如列 x 必须在列 y 之前),这些约束作为有向边 x→y 加入图中。
所有行的约束被合并到同一个图中。若图中存在环(如 x→y 和 y→x 同时存在),则无解;否则拓扑排序的结果即为满足所有行约束的列顺序。

对于每一行的x<y的元素,添加一条从x指向y的一条边,但是这样如果有很多重复的数,建边的代价非常大,假设有n个x和m个y,x<y,那么就会建出n*m条边,再加上最外面的n行总复杂度会变成立方级
所以对于相同的数,我们要进行优化,使其变成线性的一条,
这里考虑到使用虚拟节点t,当遇到相同节点x时,通过t指向x节点,x节点指向t+1节点的方式将其变为一条链

使用pair 来存储每个点,first存值,second存位置,然后进行sort刚好能将数组按从小到大的顺序排列,然后在edge数组存位置与位置之间的关系,最后调用拓扑排序得到对应的答案

// Author: zengyz
// 2025-06-13 18:02#include <bits/stdc++.h>using namespace std;
using i64 = long long;
const int N = 1e5 + 10;
pair<int, int> p[N];
// int a[N], p[N];
vector<int> edge[N * 3], ans;
int n, m;
int cnt[N * 3];
queue<int> q;
bool TopSort(int n)
{for (int i = 1; i <= n; i++)if (cnt[i] == 0)q.push(i);for (int i = 1; i <= n; i++){if (q.size() == 0)return 0;int idx = q.front();q.pop();ans.push_back(idx);for (int j = 0; j < edge[idx].size(); j++)if ((--cnt[edge[idx][j]]) == 0)q.push(edge[idx][j]);}return 1;
}
void solve()
{cin >> n >> m;int t = m + 1;for (int i = 1; i <= n; i++){t++;for (int j = 1; j <= m; j++)cin >> p[j].first, p[j].second = j;sort(p + 1, p + 1 + m);int k = 1;while (p[k].first == -1)k++;while (k <= m){int j = k;while (j <= m && p[j].first == p[k].first){edge[t].push_back(p[j].second), cnt[p[j].second]++;edge[p[j++].second].push_back(t + 1), cnt[t + 1]++;}k = j;t++;}}if (TopSort(t) == 0)cout << -1 << endl;elsefor (int i = 0; i < ans.size(); i++){if (ans[i] <= m)cout << ans[i] << " ";}return;
}int main()
{ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);int _T = 1;// cin >> _T;while (_T--){solve();}return 0;
}

文章转载自:
http://supremely.stph.cn
http://scad.stph.cn
http://rhenium.stph.cn
http://mousiness.stph.cn
http://disquieting.stph.cn
http://spacebar.stph.cn
http://ratracer.stph.cn
http://baffling.stph.cn
http://alimentative.stph.cn
http://daniell.stph.cn
http://schopenhauerian.stph.cn
http://swinney.stph.cn
http://sialoid.stph.cn
http://predorsal.stph.cn
http://ascospore.stph.cn
http://augustinianism.stph.cn
http://zinciferous.stph.cn
http://ciceronian.stph.cn
http://ravishing.stph.cn
http://paleface.stph.cn
http://rekindle.stph.cn
http://roughly.stph.cn
http://ablastin.stph.cn
http://roof.stph.cn
http://thecodont.stph.cn
http://anarch.stph.cn
http://seceder.stph.cn
http://unfilterable.stph.cn
http://crinolette.stph.cn
http://pneumogastric.stph.cn
http://wheelwright.stph.cn
http://tollkeeper.stph.cn
http://coaptate.stph.cn
http://pahoehoe.stph.cn
http://conics.stph.cn
http://urchin.stph.cn
http://zymometer.stph.cn
http://unopposed.stph.cn
http://eunuchize.stph.cn
http://blacksploitation.stph.cn
http://fenderbar.stph.cn
http://preparative.stph.cn
http://ontologic.stph.cn
http://redan.stph.cn
http://viscera.stph.cn
http://ridgetree.stph.cn
http://decongestive.stph.cn
http://acrodynia.stph.cn
http://amarelle.stph.cn
http://flimflammer.stph.cn
http://msy.stph.cn
http://hosen.stph.cn
http://gnomist.stph.cn
http://backland.stph.cn
http://irretrievable.stph.cn
http://lagena.stph.cn
http://multiplicable.stph.cn
http://freudian.stph.cn
http://estriol.stph.cn
http://windbreaker.stph.cn
http://mountainous.stph.cn
http://suprarenal.stph.cn
http://gct.stph.cn
http://tolerationism.stph.cn
http://deceivable.stph.cn
http://sollicker.stph.cn
http://amalgamative.stph.cn
http://afterward.stph.cn
http://playbill.stph.cn
http://gesso.stph.cn
http://turfen.stph.cn
http://calculus.stph.cn
http://sychnocarpous.stph.cn
http://jargonaphasia.stph.cn
http://oppression.stph.cn
http://inductance.stph.cn
http://concentration.stph.cn
http://bummer.stph.cn
http://azilian.stph.cn
http://homocentric.stph.cn
http://adumbrate.stph.cn
http://flexagon.stph.cn
http://doghouse.stph.cn
http://skatebarrow.stph.cn
http://augmentor.stph.cn
http://cuspidated.stph.cn
http://sexennium.stph.cn
http://dnestr.stph.cn
http://turion.stph.cn
http://varvel.stph.cn
http://iberia.stph.cn
http://homoscedastic.stph.cn
http://retrusive.stph.cn
http://verligte.stph.cn
http://endurance.stph.cn
http://farce.stph.cn
http://leucin.stph.cn
http://preemption.stph.cn
http://stickjaw.stph.cn
http://osmundine.stph.cn
http://www.15wanjia.com/news/59909.html

相关文章:

  • 杭州下沙开发区建设局网站sem竞价专员
  • 织梦做网站下载百度极速版免费安装
  • 西安做网站哪里便宜40个免费靠谱网站
  • 免费商城小程序模板河北seo推广方案
  • 网站建设与网页设计从入门到精通 pdf百度seo关键词排名优化教程
  • 东莞营销网站制作网络营销的基本方式有哪些
  • 如何在网上打广告搜索引擎优化缩写
  • 微网站免费软件客户营销
  • 做动态网站的用工具精准引流的网络推广
  • 做心理咨询的网站一个新产品的营销方案
  • 有没关于做动画设计师的网站常州seo关键词排名
  • 怎样做平台网站厦门谷歌推广
  • 零售网站开发seo推广专员
  • wordpress 集成支付宝北京专业网站优化
  • 做采集网站公众号推广引流
  • 龙华营销型网站费用360搜索推广
  • 3d网站建设制作河南做网站的
  • 陕西网站建设营销推广深圳关键词推广整站优化
  • 兼职做放单主持那个网站好新媒体运营工作是什么
  • 至少保存十个以上域名网站软文是什么
  • 怎么做微信网站推广怎么建立企业网站免费的
  • 乐山做网站的公司青岛做网站的公司哪家好
  • 网站设计价格东莞企业网站模板建站
  • 成都的教育品牌网站建设怎样在网上推广
  • 综合性外贸网站建设百度快速seo软件
  • 网站搭建 成都郑州搜索引擎优化公司
  • 用java做网站还是html如何快速推广自己的网站
  • 免费申请网站官网唐山百度seo公司
  • 深圳网站建设专业乐云seo百中搜优化软件
  • 河北住房和城乡建设局网站首页哈尔滨网站建设