るくすの日記 ~ Out_Of_Range ~

主にプログラミング関係

SRM 546 Div2

250: ContestWinner

やるだけ



class ContestWinner {
public:
  int getWinner(vector <int> events) {
    map<int,int>mx;
    rep(i,events.size())
      mx[events[i]] ++;
    int imx = 0;
    for(map<int,int>::iterator it = mx.begin();it != mx.end(); ++it)
      imx = max(imx,(*it).second);
    mx.clear();
    rep(i,events.size()){
      mx[events[i]]++;
      if(mx[events[i]] == imx) return events[i];
    }
  }
};



550: TwoRectangles



550にする意味はあまりなさそう...

幾何に見せかけた、やるだけゲー

int stage[1000][1000];
class TwoRectangles {
public:
  string describeIntersection(vector <int> A, vector <int> B) {
    memset(stage,0,sizeof(stage));
    for(int y = A[1]; y <= A[3]; y++)
      for(int x = A[0]; x <= A[2]; x++)
	stage[y][x] = 1;

    int W,H; W = H = 0;
    bool exist = false;
    int sx ,sy; sx = sy = 0;
    vector<string>same;
    for(int y = B[1]; y <= B[3]; y++){
      string tmp = "";
      for(int x = B[0]; x <= B[2]; x++){
	//	if(!exist && stage[y][x] == 1){ sx = x,sy = y; W = sx,H = sy,exist = true;}
	if(stage[y][x] == 1) tmp += "*";
      }
      if(tmp != "")
	same.pb(tmp);
    }
    rep(i,same.size()){
      //      cout<<same[i]<<endl;
      W = max(W,(int)(same[i].size()));
    }
    
    H = same.size();
    //    printf("%d,%d\n",W,H);
    if(W == 1 && H == 1) return "point";
    if(W == 1 || H == 1) return "segment";
    if(W > 1 && H > 1) return "rectangle";
    return "none";
  }
};