Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>#include <sstream>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstdio>
- #include <cstdlib>
- #include <cctype>
- #include <cmath>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int mx[]={1,0,-1,0};
- int my[]={0,1,0,-1};
- int lowx,lowy;
- map<pair<int,int>,int > m,vis;
- bool flag[3002][3002];
- int dfs(int x,int y,int k)
- {
- int ret =-1000000;
- queue<pair< pair<int,int>,int> >q;
- flag[x][y] = true;
- q.push(make_pair(make_pair(x,y),k));
- while(q.size())
- {
- int curx = q.front().first.first;
- int cury = q.front().first.second;
- int curk = q.front().second;
- q.pop();
- for(int i=0;i<4;i++)
- {
- if(curk<=0) continue;
- int nx = curx+mx[i];
- int ny = cury+my[i];
- if(flag[nx][ny]==false && curk>0)
- {
- flag[nx][ny] = true;
- q.push(make_pair(make_pair(nx,ny),curk-1));
- ret= max(ret,nx);
- }
- }
- }
- return ret-1002;
- }
- class TheGridDivTwo
- {
- public:
- int find(vector <int> x, vector <int> y, int k)
- {
- m.clear();
- vis.clear();
- cout<<"OK"<<endl;
- memset(flag,false,sizeof flag);
- for(int i=0;i<x.size();i++)
- {
- flag[x[i]+1002][y[i]+1002] = true;
- }
- int ans = dfs(1002,1002,k);
- return max(ans,0);
- }
- };
- template<typename T> void print( T a ) {
- cerr << a;
- }
- void print( long long a ) {
- cerr << a << "L";
- }
- void print( string a ) {
- cerr << '"' << a << '"';
- }
- template<typename T> void print( vector<T> a ) {
- cerr << "{";
- for ( int i = 0 ; i != a.size() ; i++ ) {
- if ( i != 0 ) cerr << ", ";
- print( a[i] );
- }
- cerr << "}" << endl;
- }
- template<typename T> void assert_eq( int n, T have, T need ) {
- if ( have == need ) {
- cerr << "Case " << n << " passed." << endl;
- } else {
- cerr << "Case " << n << " failed: expected ";
- print( need );
- cerr << " received ";
- print( have );
- cerr << "." << endl;
- }
- }
- template<typename T> void assert_eq( int n, vector<T> have, vector<T> need ) {
- if( have.size() != need.size() ) {
- cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements.";
- print( have );
- print( need );
- return;
- }
- for( int i= 0; i < have.size(); i++ ) {
- if( have[i] != need[i] ) {
- cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << ".";
- print( have );
- print( need );
- return;
- }
- }
- cerr << "Case " << n << " passed." << endl;
- }
- void assert_eq( int n, string have, string need ) {
- if ( have == need ) {
- cerr << "Case " << n << " passed." << endl;
- } else {
- cerr << "Case " << n << " failed: expected ";
- print( need );
- cerr << " received ";
- print( have );
- cerr << "." << endl;
- }
- }
- int main( )
- {
- TheGridDivTwo objectTheGridDivTwo;
- //test case0
- vector <int> param00;
- param00.push_back(1);
- param00.push_back(1);
- param00.push_back(1);
- param00.push_back(1);
- vector <int> param01;
- param01.push_back(-2);
- param01.push_back(-1);
- param01.push_back(0);
- param01.push_back(1);
- int param02 = 4;
- int ret0 = objectTheGridDivTwo.find(param00,param01,param02);
- int need0 = 2;
- assert_eq(0,ret0,need0);
- //test case1
- vector <int> param10;
- param10.push_back(-1);
- param10.push_back(0);
- param10.push_back(0);
- param10.push_back(1);
- vector <int> param11;
- param11.push_back(0);
- param11.push_back(-1);
- param11.push_back(1);
- param11.push_back(0);
- int param12 = 9;
- int ret1 = objectTheGridDivTwo.find(param10,param11,param12);
- int need1 = 0;
- assert_eq(1,ret1,need1);
- //
- // //test case2
- vector <int> param20;
- param20.push_back(1);
- vector <int> param21;
- param21.push_back(0);
- int param22 = 1000;
- int ret2 = objectTheGridDivTwo.find(param20,param21,param22);
- int need2 = 1000;
- assert_eq(2,ret2,need2);
- //test case3
- vector <int> param30;
- param30.push_back(1);
- param30.push_back(0);
- param30.push_back(0);
- param30.push_back(-1);
- param30.push_back(-1);
- param30.push_back(-2);
- param30.push_back(-2);
- param30.push_back(-3);
- param30.push_back(-3);
- param30.push_back(-4);
- param30.push_back(-4);
- vector <int> param31;
- param31.push_back(0);
- param31.push_back(-1);
- param31.push_back(1);
- param31.push_back(-2);
- param31.push_back(2);
- param31.push_back(-3);
- param31.push_back(3);
- param31.push_back(-4);
- param31.push_back(4);
- param31.push_back(-5);
- param31.push_back(5);
- int param32 = 47;
- int ret3 = objectTheGridDivTwo.find(param30,param31,param32);
- int need3 = 31;
- assert_eq(3,ret3,need3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment