Example #1
0
int main(){
	int flag,stick,sum;
	Sticks s;
	while(cin>>flag){
		if(flag==0){
			break;
		}
		s.init();
		for(int i=0;i<flag;i++){
			cin >> stick;
			s.push(stick);
		}
		s.finish_input();

		//s.dump(s.calc);
		//s.dump();
		//cout << s.sum << endl;
		// for(int i=0;i<flag;i++){
		// 	cout << sticks[i] << " ";
		// }
		// cout << endl;

	}
	return 0;
}
Example #2
0
int main(){
  int t; Sticks s;

  while (cin>>t) {
    if (t == 0) { break; }

    s.reset(t);
    
    for (int i = t; i > 0; i--) {
      cin>>t;
      s.push(t);
    }

    cout<<s.min_original_len()<<"\n";
  }

  return 0;
}
Example #3
0
int main(void){
    int T; cin >> T;
    
    for (int t = 0; t < T; t++){
        Sticks sticks; 
        int n; cin >> n;
        for (int i = 0; i < n; i++){
            int l_i, w_i; cin >> l_i >> w_i;
            sticks.push_back(Stick(l_i, w_i));
        }

        sort(sticks.begin(), sticks.end());
        Sticks::iterator sticks_end = unique(sticks.begin(), sticks.end());

        // Insert all sticks into stick groups        
        StickGroups sgs;

        //StickGroup fst; fst.largest = Stick(0,0); sgs.push_back(fst);

#ifndef ONLINE_JUDGE
        print_stickgroups(sgs);
#endif //ONLINE_JUDGE

        for(Sticks::iterator it = sticks.begin(); it != sticks_end; ++it){

#ifndef ONLINE_JUDGE
            cerr << " insert: "; print_stick(*it); cerr << endl; //debug
#endif //ONLINE_JUDGE

            // Choose a stick group s.t. min(|it->second - sgs[i].largest|)
            StickGroup s(*it); //s.push_back(*it); s.largest = *it;
            StickGroups::iterator sgi = upper_bound(sgs.begin(), sgs.end(), s, StickGroupComparator());
          
            if (sgi == sgs.begin()){

#ifndef ONLINE_JUDGE
                cerr << "  sgi == sgs.begin()" << endl;
#endif //ONLINE_JUDGE

                sgs.push_back(s);
            }
            else {

#ifndef ONLINE_JUDGE
                cerr << "  sgi != sgs.begin()" << endl;
#endif //ONLINE_JUDGE

                advance(sgi,-1);
                sgi->largest = s.largest;

#ifndef ONLINE_JUDGE
                sgi->push_back(s.back());
#endif //ONLINE_JUDGE

            } 
            sort(sgs.begin(), sgs.end(), StickGroupComparator());
#ifndef ONLINE_JUDGE
            print_stickgroups(sgs);
#endif //ONLINE_JUDGE
        }
        
        cout << sgs.size() << endl;
    }
    return 0;
}