SRM 620 D1L2: CandidatesSelection, Greedy
来源:互联网 发布:淘宝申请退款 编辑:程序博客网 时间:2024/05/17 23:42
题目:http://community.topcoder.com/stat?c=problem_statement&pm=13144&rd=15853
逆向选择,不断剔除条件。
代码:
#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <iostream>#include <sstream>#include <iomanip>#include <bitset>#include <string>#include <vector>#include <stack>#include <deque>#include <queue>#include <set>#include <map>#include <cstdio>#include <cstdlib>#include <cctype>#include <cmath>#include <cstring>#include <ctime>#include <climits>using namespace std;#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)typedef pair<int, int> pii;typedef long long llong;typedef pair<llong, llong> pll;#define mkp make_pair#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); ++it)/*************** Program Begin **********************/class CandidatesSelection {public: string possible(vector <string> score, vector <int> result) {vector < pii > cond;int n = result.size();int m = score[0].size();for (int i = 0; i < n - 1; i++) {cond.push_back( mkp(result[i], result[i + 1]) );}bool used[55];memset(used, 0, sizeof(used));while (!cond.empty()) {bool isIndex = true;int r = cond.size();for (int i = 0; i < r; i++) {isIndex &= (cond[i].first < cond[i].second);}if (isIndex) {break;}bool removed = false;for (int i = 0; i < m; i++) {if (used[i]) {continue;}bool ok = true;for (int j = 0; j < r; j++) {ok &= ( score[ cond[j].first ][i] <= score[ cond[j].second ][i] );}if (!ok) {continue;}used[i] = true;vector < pii > newcond;for (int j = 0; j < r; j++) {if (score[ cond[j].first ][i] == score[ cond[j].second ][i]) {newcond.push_back(cond[j]);}}if (newcond.size() == cond.size()) {continue;}removed = true;cond = newcond;break;}if (!removed) {return "Impossible";}}return "Possible"; }};/************** Program End ************************/
0 0
- SRM 620 D1L2: CandidatesSelection, Greedy
- SRM 615 D1L2: LongLongTripDiv1
- SRM 574 D1L2:PolygonTraversal,dp
- SRM 621 D1L2: TreesAnalysis,DFS
- SRM 571 D1L2:MagicMolecule,brute force
- SRM 629 D1L2: CandyCollection, dp, dfs
- SRM 573 D1L2:SkiResorts,最短路径算法
- SRM 572 D1L2:EllysBulls,Brute Force,meet in the middle
- SRM 626 D1L2:CatchTheBeat,Longest increasing subsequence,O(NlogN) 算法
- SRM 624 D1L2:DrivingPlans,求解所有的最短路径
- SRM 605 D1 L1 :AlienAndHamburgers,Greedy
- SRM 627 D1L2:GraphInversions,DFS,求所有指定长度的路径, Binary indexed tree (BIT)
- SRM 620
- Greedy
- Greedy
- Greedy
- srm
- SRM 620 D2L3: RandomGraph, dp
- strstr
- 【处女作】先介绍一下自己
- struts2限制单元格字数
- longjmp setjmp 简单用法
- Java的向上转型和向下转型
- SRM 620 D1L2: CandidatesSelection, Greedy
- LIB和DLL的区别与使用
- BZOJ 2878([Noi2012]迷失游乐园-树形DP+环加外向树+期望DP+vector的erase)
- MAC系统XAMPP 中 MySQL命令行客户端配置使用
- Mysql权限管理白皮书
- ibatis简单入门
- CRC学习笔记
- 解决领取红包产生并发的几个小方法
- 英文