Topcoder srm631 div2 solution report

Source: Internet
Author: User

250: the grid has two colors. The maximum value of the longest continuous color in a column in the grid is the same.

Solution: violence.

Solution code:

// 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;        }        };
View code

500, ask if you can make each location have at most one cat.

Solution: sort the vertices of a cat and put all the cats on the left as much as possible. If the cat cannot be placed on the left or there is no repeating interval, it is impossible.

Solution code:

 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 };
View code

 

Topcoder srm631 div2 solution report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.