首页 > 代码库 > Topcoder SRM631 DIV2 解题报告
Topcoder SRM631 DIV2 解题报告
250:网格有两种颜色,网格中一列最长的连续的颜色相同的最大值。
解题思路:暴力。
解题代码:
// BEGIN CUT HERE/**/// END CUT HERE#line 7 "TaroGrid.cpp"#include <cstdlib>#include <cctype>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <iostream>#include <sstream>#include <map>#include <set>#include <queue>#include <stack>#include <fstream>#include <numeric>#include <iomanip>#include <bitset>#include <list>#include <stdexcept>#include <functional>#include <utility>#include <ctime>using namespace std;#define PB push_back#define MP make_pair#define REP(i,n) for(i=0;i<(n);++i)#define FOR(i,l,h) for(i=(l);i<=(h);++i)#define FORD(i,h,l) for(i=(h);i>=(l);--i)typedef vector<int> VI;typedef vector<string> VS;typedef vector<double> VD;typedef long long LL;typedef pair<int,int> PII;class TaroGrid{ public: int getNumber(vector <string> grid) { int n = grid[0].size(); int mx = 1; int len = grid.size(); for(int i = 0 ;i < n ;i++) { int temp = grid[0][i]; int sum = 1 ; for(int j = 1;j < len ;j ++) { if(grid[j][i] == temp) { sum ++ ; }else { sum = 1 ; temp = grid[j][i]; } if(sum > mx) mx = sum ; } } return mx; } };
500:无限长的数轴有某些位置有给定数目的猫,每一秒猫可以呆在原地和向左右走,给你限制时间,问你能否让每个位置最多只有一个猫。
解题思路:对有猫的点排序,把所有的猫尽可能往左边放,如果放不下,或者不能把每个有重复区间,则不可能
解题代码:
1 // BEGIN CUT HERE 2 /* 3 4 */ 5 // END CUT HERE 6 #line 7 "CatsOnTheLineDiv2.cpp" 7 #include <cstdlib> 8 #include <cctype> 9 #include <cstring>10 #include <cstdio>11 #include <cmath>12 #include <algorithm>13 #include <vector>14 #include <string>15 #include <iostream>16 #include <sstream>17 #include <map>18 #include <set>19 #include <queue>20 #include <stack>21 #include <fstream>22 #include <numeric>23 #include <iomanip>24 #include <bitset>25 #include <list>26 #include <stdexcept>27 #include <functional>28 #include <utility>29 using namespace std;30 31 #define PB push_back32 #define MP make_pair33 34 #define REP(i,n) for(i=0;i<(n);++i)35 #define FOR(i,l,h) for(i=(l);i<=(h);++i)36 #define FORD(i,h,l) for(i=(h);i>=(l);--i)37 38 typedef vector<int> VI;39 typedef vector<string> VS;40 typedef vector<double> VD;41 typedef long long LL;42 typedef pair<int,int> PII;43 44 struct node{45 int x, y; 46 }cat[100];47 bool cmp(node a, node b )48 {49 return a.x < b.x;50 }51 class CatsOnTheLineDiv252 {53 public:54 string getAnswer(vector <int> p, vector <int> c, int t)55 {56 int n = p.size();57 for(int i = 0 ; i< n;i ++ )58 {59 cat[i].x = p[i];60 cat[i].y = c[i];61 }62 sort(cat,cat+n,cmp);63 int s = -1e9;64 int ok = 1;65 for(int i = 0 ;i < n;i ++)66 {67 68 int k1 = max(s+1,cat[i].x-t);69 int k2 = k1 + cat[i].y -1;70 //printf("%d %d\n",k1,k2);71 if(k2 - cat[i].x > t)72 ok = 0 ; 73 s = k2;74 }75 if(!ok)76 return "Impossible";77 else return "Possible";78 79 }80 81 82 };
Topcoder SRM631 DIV2 解题报告
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。