I'm Telling the Truth HDU
来源:互联网 发布:淘宝固定背景怎么设置 编辑:程序博客网 时间:2024/06/04 18:33
题目传送门
题意:在一次考试之后,给你其中n个学生的考试排名的范围,问这其中最多有多少个可能是正确的。如果人数相等的话输出字典序最大的一组。
思路:比赛的时候看到这个题目第一反应是贪心,但是继续往下就没有了思路,后来发现这个其实是一个二分图匹配,但是自己不知道怎么匹配了,然后就在场上对这个序列正反排序进行贪心(面向样例编程),并没有做出来,场下看了题解发现用匈牙利算法就可以了,还是不难的,只有把匹配的方法想好了就行。然后最后从大到小进行匹配使得字典序尽可能的大。
#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <fstream>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#include <sstream>#include <list>#define MAXN 110#define INF 10000000#define MOD 1000000007#define LL long long#define pi acos(-1.0)using namespace std;vector<int> vec[MAXN];vector<int> vector1;int match[MAXN * 1000];int check[MAXN * 1000];bool dfs(int x) { for (int i = 0; i < vec[x].size(); ++i) { int to = vec[x][i]; if (!check[to]) { check[to] = 1; if (match[to] == -1 || dfs(match[to])) { match[to] = x; //match[x] = to; return true; } } } return false;}int main() { std::ios::sync_with_stdio(false); int T; cin >> T; for (int kase = 1; kase <= T; ++kase) { memset(match, -1, sizeof(match)); memset(vec, 0, sizeof(vec)); int n; cin >> n; int x, y; for (int i = 1; i <= n; ++i) { cin >> x >> y; for (int j = x; j <= y; ++j) { vec[i].push_back(j); } } vector1.clear(); for (int i = n; i >= 1; --i) { memset(check, 0, sizeof(check)); if (dfs(i)) vector1.push_back(i); } sort(vector1.begin(), vector1.end()); cout << vector1.size() << endl; for (int i = 0; i < vector1.size(); ++i) { if (i == vector1.size() - 1) cout << vector1[i] << endl; else cout << vector1[i] << " "; } } 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(入门级别)
- 容斥原理 学习 M
- String, StringBuffer,StringBuilder的区别
- Dijkstra算法和Floyd算法
- Ajax上传文件返回参数
- sublime写python3可以添加的插件
- I'm Telling the Truth HDU
- 使用QJM构建HDFS HA架构(2.2+)
- py4j——用python访问java遇到的问题解决
- 酒客项目日志20170807
- android webView加载126邮箱 提示系统繁忙
- 第一章:初涉MySQL
- xadmin的使用方法
- iOS 面试题
- 解决android 7.0系统,调用相机报:android.os.FileUriExposedException错