Monday, February 7, 2011

TopCoder SRM 293, DIV II, Aquarium

Problem Statement

You have a fish aquarium. You are given a int[] fishSizes, denoting the size of each fish in the aquarium. They've been getting along pretty well so far, but you would now like to add a new fish (called Bob). You know that fish sometimes eat each other. You estimate that a fish might eat another fish if and only if it is at least two times larger, but no more than ten times larger, than that other fish.

Considering this, you would like to choose Bob's size such that:

- Bob is not in danger of being eaten by any other fish (i.e., its size is not between 1/10 and 1/2, inclusive, the size of any other fish).

- Bob is not tempted to eat any other fish (i.e., no other fish in the aquarium has a size between 1/10 and 1/2, inclusive, of Bob's size).

Your task is to return the number of different integer sizes for Bob between minSize and maxSize, inclusive, that won't cause any eating "conflicts" with other fish.



#include <iostream>
#include <vector>
using namespace std;
#define sz(v) ((int)(v).size())
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define repe(i,a,n)  for(int i=(a);i<=(n);i++)
#define forsz(i,a,v) rep(i,a,sz(v))
#define repsz(i,v) rep(i,0,sz(v))
#define vi vector<int>
class Aquarium {

public:

int peaceful(int minSize, int maxSize, vector <int> fishSizes) {
 int ans=0,flag;float bob;
 int mint=minSize,maxt=maxSize;vi f(fishSizes);
 repe(i,mint,maxt){
   bob=(float)i;
   flag=0;
   repsz(j,f){
     if((bob/f[j]>0.0999&&bob/f[j]<=0.5)||(bob/f[j]>=2&&bob/f[j]<=10))
{if(bob==1)cout<<"haha"<<endl;flag=1;}
   }
   if(!flag)ans++;
 }
 return ans;
}
};

No comments:

Post a Comment