I'm Telling the Truth HDU
来源:互联网 发布:抽奖软件注册机 编辑:程序博客网 时间:2024/05/16 07:25
题目描述:每位同学说了自己名次所在的范围,有人可能说谎了,求最多有多少人说的是实话。
思路:一开始没想明白,学弟说贪心试试,但这想法立马被我给否了,没有贪心策略符合所有情况。对桌的学弟看了题后一直大喊这是二分图最大匹配问题我做过啊,我一开始以为他在开玩笑没当回事。后来想了想,还真是一道很裸的二分匹配模板题。靠年轻人的思路写的,很惭愧啊。
代码如下:
#include<iostream>#include<cstdio>#include<vector>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<string>#include<iostream>using namespace std;int const maxn = 100000 + 66;vector<int> g[200];bool vis[maxn];int match[maxn];int n;bool dfs(int v){ vis[v] = true; int len = g[v].size(); for(int i = 0; i < len; ++i){ int u = g[v][i], w = match[u]; if(w < 0 || !vis[w] && dfs(w)){ match[v] = u; match[u] = v; return true; } } return false;}int main(){ int t; scanf("%d", &t); while(t--){ for(int i = 0; i < 200; ++i) g[i].clear(); int u, v; scanf("%d", &n); for(int i = 0; i < n; ++i){ scanf("%d%d", &u, &v); for(int j = u; j <= v; ++j){ g[i].push_back(60 + j); } } int cnt = 0; memset(match, -1, sizeof match); for(int i = n - 1; i >= 0; --i){ if(match[i] < 0){ memset(vis, 0, sizeof vis); if(dfs(i))++cnt; } } printf("%d\n", cnt); bool ok = false; for(int i = 0; i < n; ++i){ if(match[i] >= 0){ if(ok) printf(" "); else ok = true; printf("%d", i + 1); } } printf("\n"); } return 0;}
阅读全文
0 0
- HDU 3729 I'm Telling the Truth
- HDU 3729 I'm Telling the Truth
- HDU 3729I'm Telling the Truth
- hdu 3729 I'm Telling the Truth
- HDU 3729 I'm Telling the Truth
- HDU 3729 I'm Telling the Truth
- I'm Telling the Truth HDU
- I'm Telling the Truth HDU
- I'm Telling the Truth
- hdu 3279 I'm Telling the Truth 二分匹配
- hdu 3729 I'm Telling the Truth(最大匹配)
- hdu 3729 I'm Telling the Truth 二分图匹配
- 【HDU】3729 I'm Telling the Truth 离散+最大流
- hdu 3729 I'm Telling the Truth(贪心)
- HDU 3729 — I'm Telling the Truth
- hdu 3729 I'm Telling the Truth(二分图匹配)
- hdu 3729 I'm Telling the Truth【二分匹配】
- HDU 3729 I'm Telling the Truth(入门级别)
- C语言——实例023 打印菱形
- 【解决方案】Axure RP如何隐藏部分页面的菜单项
- 选择结构
- 【CDC翻客】移动端App测试实用指南
- 有限扩散集团凝聚模型第二讲: DLCA模型的形态分析
- I'm Telling the Truth HDU
- 【Jiya&Chieng】(零)Jiya和Chieng的故事
- Docker之网桥保存-yellowcong
- Uva 804 Spatial Structures
- 【自考】软件开发工具(第一遍)
- HDU 2391 Filthy Rich
- C_线性表----duque双端队列容器
- 吃糖果||HDU1205
- [Lydsy2017年4月月赛]抵制克苏恩