back_slash's blog

By back_slash, history, 3 months ago, In English,

I am writing this blog mainly for 2 reasons. One is to discuss the problems. I want to know what is the logic behind C Large. And also if we can get a count of how many people got full points in the round.

 
 
 
 
  • Vote: I like it  
  • +25
  • Vote: I do not like it  

»
3 months ago, # |
  Vote: I like it +24 Vote: I do not like it
Hint
  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hint for B please ?

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It's Greedy. First sort the given array. Then check if you can dance. If you can't dance, check if you can recruit.

      From the available teams, for dancing, dance with the team which has least energy. And for recruiting, recruit the team which has highest energy.

      Main logic
    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      The following observations were important:

      • You can process the teams in any order (ie. decide to dance, recruit or truce) because if he current one isn't the one you want to process you can just make an excuse

      • Recruiting is most beneficial when done against highest energy teams

      • Dancing is most beneficial when done against lowest energy teams

  • »
    »
    3 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Can you elaborate a bit more please(for C large) ?

»
3 months ago, # |
  Vote: I like it +15 Vote: I do not like it

My solutions

Problem 1.

Ans

Problem 2.

Ans

Problem 3.

Ans

Problem 4.

Ans
»
3 months ago, # |
  Vote: I like it -27 Vote: I do not like it

For problem B, my solution is incorrect. Can some body help here?

My code

#include <bits/stdc++.h>

using namespace std;

int energy, N;
vector<int> vec;
int ans;

int funcc(vector<int> vv, int ind, int en){

  if(ind == vv.size())
    return 0;

  int x = vv[ind];
  int ret = INT_MIN;
  //dance
  if(en - x > 0)
    ret = 1 + funcc(vv, ind + 1, en - x);

  //truce
  ret = max(ret, funcc(vv, ind + 1, en));

  //recruit
  ret = max(ret, funcc(vv, ind+1, en + x) - 1);

  //delay
  if(ind < vec.size()){
    vv.push_back(x);
    ret = max(ret, funcc(vv, ind + 1, en));
  }

  return ret;
}
int main(){

  freopen("B-small-attempt1.in","r",stdin);
  freopen("output_file_name.out","w",stdout);
  int tc;
  cin>>tc;
  for(int t = 1; t <= tc; t++){
    cin>>energy>>N;
    vec.clear();
    int x;
    for(int i=0; i<N; i++){
      cin>>x;
      vec.push_back(x);
    }
    ans = 0;

    ans = funcc(vec, 0, energy);
    cout<<"Case #"<<t<<": "<<ans<<endl;
  }
  return 0;
}
»
2 months ago, # |
  Vote: I like it +8 Vote: I do not like it

What is with the ranking? It shows my rank when I am logged in but not otherwise??