예제 #1
0
파일: 10474.cpp 프로젝트: liuhb86/uva
int main(){
	int cases=0;
	while(1){
		int n,q;
		cin>>n>>q;
		if(n==0) break;
		++cases;
		cout<<"CASE# "<<cases<<":"<<endl;
		marble.clear();
		int k;
		for(int i=0;i<n;++i) {cin>>k;marble.push_back(k);}
		sort(marble.begin(),marble.end());
		for(int i=0;i<q;i++){
			cin>>k;
			Vec::iterator it=lower_bound(marble.begin(),marble.end(), k);
			if(it!=marble.end() && *it==k){
				cout<<k<<" found at "<<it-marble.begin()+1<<endl;
			}else{
				cout<<k<<" not found"<<endl;

			}
		}
	}
	return 0;	
}
예제 #2
0
파일: ascendvec.cpp 프로젝트: herumi/misc
 uint32_t get(uint32_t pos) const
 {
     assert(!v_.empty() && v_[0] == 0);
     Vec::const_iterator i = std::lower_bound(v_.begin(), v_.end(), pos + 1);
     if (i == v_.end()) return (uint32_t)v_.size() - 1;
     return (uint32_t)std::distance(v_.begin(), i) - 1;
 }
예제 #3
0
파일: 10048.cpp 프로젝트: liuhb86/uva
int main(){
	int kase =0;
	while(true){
		int c,s,q;
		cin>>c>>s>>q;
		if (c==0) break;
		++kase;
		edges.clear();
		for(int i=0;i<s;++i){
			Edge e;
			cin>>e.from>>e.to>>e.weight;
			edges.push_back(e);
		}
		sort(edges.begin(), edges.end());
		for(int i=1;i<=c;++i){
			nodes[i].parent = nodes+i;
			nodes[i].count = 0;
			nodes[i].edges.clear();
		}
		int count =0;
		for(Vec::iterator it = edges.begin(); count< c-1 && it!= edges.end(); ++it){
			Node *rs = getRoot(it->from), *rt = getRoot(it->to);
			if(rs == rt) continue;
			if (rs->count > rt->count){
				rt->parent = rs;
				rs->count+=rt->count;
			} else {
				rs->parent = rt;
				rt->count += rs->count;
			}
			++count;

			nodes[it->from].edges.push_back(*it);
			int tmp = it->to;
			it->to = it->from; it->from =tmp;
			nodes[it->from].edges.push_back(*it);
		}
		if (kase >1) cout<<endl;
		cout<<"Case #"<<kase<<endl;
		for(int i=0;i<q; ++i){
			int s,t;
			cin>>s>>t;
			CalcResult result = calc(s,t,0);
			if (result.reached) {
				cout<<result.value<<endl;
			} else {
				cout<<"no path"<<endl;
			}
		}
	}
	return 0;
}
예제 #4
0
 static double mult(Vec& u, Vec& v)
 {
   double s = 0.;
   Vec::const_iterator it = u.begin();
   for(;it != u.end(); it ++) {
     const unsigned int i = it->first;
     if(v.find(i) != v.end()) {
       double t = it->second;
       s += t * v[i];
     }
   }
   return s;  
 }
예제 #5
0
 static void print(const Vec& u)
 {
   Vec::const_iterator it = u.begin();
   for(;it != u.end(); it ++) {
     printf("v[%d] = %lf\n", it->first, it->second);
   }
 }
예제 #6
0
int main(int argc, const char *argv[])
{
    Vec<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;

    while (record.read(cin)) {
        maxlen = max(maxlen, record.name().size());
        students.push_back(record);
    }

    //  
    sort(students.begin(), students.end(), compare);

    for (Vec<double>::size_type i = 0; i != students.size(); i++) {
        cout << students[i].name() << string(maxlen + 1 - students[i].name().size(), ' ');
        try {
            double final_grade = students[i].grade();
            streamsize prec = cout.precision();
            cout << setprecision(3) << final_grade << setprecision(prec) << endl;
        } catch (domain_error e) {
            cout << e.what() << endl;
        }
    }
    return 0;
}
예제 #7
0
TEST(VectorMapTest, EmptyTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	ASSERT_TRUE(v.end() == v.find(10));
}
예제 #8
0
double average_analysis(const Vec<Student_info>& students)
{
    Vec<double> grades;

    transform(students.begin(), students.end(),
              back_inserter(grades), average_grade);
    return median(grades);
}
 void
 __expect_found (E const& elm, Iter const& targetPos)
 {
     if (targetPos == orig_.end())
         throw error::State(_Fmt("Premature end of sequence; unable to locate "
                                 "element %s in the remainder of the target.") % elm
                            , LUMIERA_ERROR_DIFF_CONFLICT);
 }
예제 #10
0
 void
 find (E const& elm)  override
 {
     __expect_further_elements (elm);
     Iter found = std::find(pos_, orig_.end(), elm);
     __expect_found (elm, found);
     seq_.push_back (move(*found));
 }      // consume and leave waste, expected to be cleaned-up by skip() later
예제 #11
0
파일: vecalg.hpp 프로젝트: sig-vip/skeleton
void apply1_wores_vec (Vec& a, UFunc f)
{
    if(a.is_empty())
        return;
    typedef typename cnc_iterator<Vec>::type Iter;
    for(Iter i = a.begin(), iend = a.end(); i != iend; ++i)
        f(*i);
}
예제 #12
0
      ~GeneratedCode() {
         /*
          * Deallocate things as previously requested and
          * free shared manager when no longer used.
          */
#if HAVE_LLVM < 0x0306
         Vec::iterator i;

         assert(TheMM);
         for ( i = FunctionBody.begin(); i != FunctionBody.end(); ++i )
            TheMM->deallocateFunctionBody(*i);
#if HAVE_LLVM < 0x0304
         for ( i = ExceptionTable.begin(); i != ExceptionTable.end(); ++i )
            TheMM->deallocateExceptionTable(*i);
#endif /* HAVE_LLVM < 0x0304 */
#endif /* HAVE_LLVM < 0x0306 */
      }
예제 #13
0
int main(int argc, char* argv[])
{
    int rank,size,offset;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
  
    ostringstream convert;
    convert << rank+1;
    string file = "data"+ convert.str();
    int numLocal, totalNode;
    Graph g(rank,file);

    Matpair buf(4);
    Vec F;
    numLocal = g.localNode();
    offset = rank*numLocal;
    int root = 512;
    int finish,localfinish;
    int parents[numLocal];
    for (int i=0;i<numLocal;i++){
        parents[i] = -1;
    }
    if (rank == root/numLocal){
        F.push_back(root);
        parents[root-offset] = -2;}
    localfinish = !F.empty(); 

    Vec nxFr;
   
    int dep=0;
    int depth[numLocal];
    for (int i = 0; i < numLocal; i++){
	    depth[i]=0;
    }

    while(1){
    	localfinish=!F.empty();
	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Allreduce(&localfinish,&finish,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
    	if (finish==0)
		break;
        if (!F.empty()){
	   for (Vec::iterator i = F.begin();i != F.end(); i++){
		depth[*i-offset] = dep+1;
		cout << "node "<< *i <<" depth: "<<dep+1<<endl;
	   }
	}

        nextFrBuf(g,F,rank,size,buf,offset);
        alltoallPersonalized(buf,parents,nxFr,size,offset);
	F=nxFr;
	dep++;
    } 

    MPI_Finalize();
    return 0;
}
예제 #14
0
TEST(VectorMapTest, InsertTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	v.insert(10, 1);
	ASSERT_TRUE(v.end() != v.find(10));
	Pair const& p = *(v.find(10));
	ASSERT_EQ(1, p.second);
}
예제 #15
0
파일: urls_main.cpp 프로젝트: arraytools/C
int main() {
        string s;
        while (getline(cin, s)) {
                Vec<string> v = find_urls(s);
                for (Vec<string>::const_iterator i = v.begin();
                        i != v.end(); ++i)
                        cout << *i << endl;
        }
        return 0;
}
예제 #16
0
 T pop() {
     if (front->empty()) {
         js::Reverse(back->begin(), back->end());
         Vec *tmp = front;
         front = back;
         back = tmp;
     }
     T item = front->back();
     front->popBack();
     return item;
 }        
예제 #17
0
파일: vecalg.hpp 프로젝트: sig-vip/skeleton
void apply2_wores_vec_by_val (Vec& a, Val& b, BinOp f)
{
    if(a.is_empty())return;

    typename cnc_iterator<Vec>::type
        ai = a.begin(),
        aend = a.end();

    for(; ai != aend; ++ai)
        f(*ai, b);
}
예제 #18
0
파일: arrayMap.cpp 프로젝트: nodakai/exp
    void repack() {
        // dump();

        const int oWidth = (m_vec.size() - 1 - 1) / 2, nWidth = 2 * oWidth; // half widths
        Vec v(2 * nWidth + 1 + 1);
        copy(m_vec.begin() + 1, m_vec.end(), v.begin() + oWidth + 1);
        if ( ! m_vec.empty())
            v[0] = m_vec[0];
        swap(m_vec, v);
        m_minKey -= oWidth; m_maxKey += oWidth;
    }
예제 #19
0
파일: vecalg.hpp 프로젝트: sig-vip/skeleton
void apply2_wores_val_by_vec (Val& a, Vec& b, BinOp f)
{
    if(b.is_empty())return;

    typename cnc_iterator<Vec>::type
        bi = b.begin(),
        bend = b.end();

    for(; bi != bend; ++bi)
        f(a, *bi);
}
예제 #20
0
파일: Lib.cpp 프로젝트: wwbrannon/BayesTree
double Lib::median(Vec x)
{
        typedef std::vector<double>::size_type vec_sz;

        vec_sz size = x.size();
        if(size==0)
                throw std::domain_error("median of an empty vector");

        std::sort(x.begin(),x.end());
        vec_sz mid = size/2;
        return size%2 == 0 ? (x[mid]+x[mid-1])/2 : x[mid];
}
예제 #21
0
파일: rep.cpp 프로젝트: comenerv/Boom
 Vec rep(const Vec &x, uint n){
   uint m = x.size();
   Vec ans(m*n);
   Vec::const_iterator b = x.begin();
   Vec::const_iterator e = x.end();
   Vec::iterator out = ans.begin();
   for(uint i=0; i<n; ++i){
     std::copy(b,e,out);
     out+=m;
   }
   return ans;
 }
예제 #22
0
파일: vecalg.hpp 프로젝트: sig-vip/skeleton
bool allcmp_val_by_vec (const Val& val, const Vec& a, Cmp cmp)
{
    typename Vec::const_iterator
        ia = a.begin(),
        iaend = a.end();

    for(; ia != iaend; ++ia)
        if(!cmp(val, *ia))
            return false;

    return true;
}
예제 #23
0
int main()
{
	string s;
	while (getline(cin, s))
	{
		Vec<string> v = find_urls(s);
		for (Vec<string>::const_iterator it = v.begin(); it != v.end(); ++it)
			cout << *it << endl;
	}

	system("pause");
	return 0;
}
예제 #24
0
int main()
{
    Str s;
    Vec<Str> v;
    while(getline(std::cin, s)) {
        v = findurl(s);
    }
    
    for(Vec<Str>::const_iterator i = v.begin(); i != v.end(); ++i)
        std::cout << *i << std::endl;
    
     return 0;
}
예제 #25
0
bool BoolOpSeq::simplify_and_seq( Vec<Item> &and_seq ) {
    for( int i = 0; i < and_seq.size(); ++i ) {
        for( int j = i + 1; j < and_seq.size(); ++j ) {
            if ( and_seq[ i ].expr == and_seq[ j ].expr ) {
                if ( and_seq[ i ].pos != and_seq[ j ].pos )
                    return true; // c and not c
                // c and ... and c
                and_seq.remove( j-- );
            }
        }
    }
    std::sort( and_seq.begin(), and_seq.end(), SortByExpr() );
    return false;
}
예제 #26
0
파일: main2.cpp 프로젝트: arraytools/C
// compute the median of a `Vec<double>'
// note that calling this function copies the entire argument `Vec'
double median(Vec<double> vec)
{
	typedef Vec<double>::size_type vec_sz;

	vec_sz size = vec.size();
	if (size == 0)
		throw domain_error("median of an empty Vec");

	sort(vec.begin(), vec.end());

	vec_sz mid = size/2;

	return size % 2 == 0 ? (vec[mid] + vec[mid-1]) / 2 : vec[mid];
}
예제 #27
0
int main()
{
    Vec<char> v = {'H', 'e', 'l', 'l', 'o', ',', 'w', 'o', 'r', 'l', 'd', '!'};
    for(const auto &c : v)
        cout << c;
    cout << endl;
    v.push_back(':');
    v.push_back(')');
    cout << v.size() << endl;
    cout << v.capacity() << endl;
    for(auto iter = v.begin(); iter != v.end(); ++iter)
        cout << *iter;
    cout << endl;
    return 0;
}
예제 #28
0
static bool hasMechanism (const String & name, const XMLChunk & features) {
	XMLChunk mechanisms = features.getChild ("mechanisms");
	if (mechanisms.error()) return false;
	String nameUppered (name);
	boost::algorithm::to_upper(nameUppered);
	typedef std::vector<const XMLChunk*> Vec;
	Vec elements = mechanisms.getChildren("mechanism");
	for (Vec::const_iterator i = elements.begin(); i != elements.end(); i++) {
		const XMLChunk * chunk (*i);
		String text = chunk->text();
		boost::algorithm::to_upper (text);
		if (text == nameUppered) return true;
	}
	return false;
}
예제 #29
0
//note that vector v will be overwritten!!!
inline int median(Vec<int> v){
    int len = v.len;
    if (len == 1) return v[0];
    if (len == 2) return (v[0] + v[1])/2;
    
    //general case. I am not using partial sorting here, but I don't 
    //expect more than 100 elements, so it shouldn't make a big difference...
    std::sort(v.begin(), v.end());
    int mid = (len-1) >> 1;
    if (len & 1){//odd number
        return v[mid];
    } else {//even number
        return (v[mid] + v[mid+1]) >> 1;
    }
}
예제 #30
0
void
 SIR_scheme::observe_likelihood (const Vec& lw)
/*
 * Observation fusion directly from likelihood weights
 * lw may be smaller then the number of particles. Weights for additional particles are assumed to be 1
 * Pre : wir previous particle likelihood weights
 * Post: wir fused (multiplicative) particle likehood weights
 */
{
					// Weight Particles. Fused with previous weight
	Vec::const_iterator lw_end = lw.end();
	for (Vec::const_iterator lw_i = lw.begin(); lw_i != lw_end; ++lw_i) {
		wir[lw_i.index()] *= *lw_i;
	}
	wir_update = true;
}