Example #1
0
        vector <int> getminmax(int N, int K)
            {
		VI res;
		res.PB(max(N-K,0));
		res.PB(max(0,N- ((K+1)/2)));
		return res;
            }
Example #2
0
void sieve()
{
    int sq=sqrt(MAXN);

    for(int i=3;i<=sq;i+=2)
    {
        if(!bs.test(i))
        {
            for(int j=i*i;j<MAXN;j+=i)
            {
                bs.set(j);
            }
        }
    }

    primes.PB(2);

    for(int i=3;i<MAXN;i+=2)
    {
        if(!bs.test(i))
        {
            primes.PB(i);
        }
    }

    plen=primes.size();


}
Example #3
0
void MAIN()
{
    VI v;
    int ti;

    for(int i=0; i<9; ++i)
    {
        scanf("%d",&ti);
        //printf("%d\n",ti);
        v.PB(ti);
    }

    int n=encode(v);
    if(!n)
    {
        printf("\n");
    }
    else
    {
        solve(n);
        VI v;
        while(n)
        {
            v.PB(arr[n]);
            n=prevv[n];
        }

        reverse(v.begin(),v.end());
        for(int i=0; i<v.size()-1; ++i)
        {
            printf("%d ",v[i]);
        }
        printf("%d\n",v[v.size()-1]);
    }
}
Example #4
0
	REP(i,Q)
	{
		qid.PB(SI);
		qsz.PB(SI);
		VI v;
		REP(j,qsz[i])
		{
			v.PB(SI);
		}
Example #5
0
File: 924.cpp Project: gm561/acm
    void bfs(int s) {
        VI q; q.PB(s); g[s].d = 0;

        for(size_t i = 0; i < q.size(); ++i) {
            FOREACH(it, g[q[i]]) if(g[it->to].d == INF) {
                g[it->to].d = g[q[i]].d + 1;
                q.PB(it->to);
            }
        }
    }
Example #6
0
VI next(VI v) {
  map<int,int> cnt; FOZ(i,v) ++cnt[v[i]];
  VI ret;
  FOREACH(it, cnt) {
    ret.PB(it->second);
    if(it->second > 9) {
      throw it->second;
    }
    ret.PB(it->first);
  }
Example #7
0
   int differentOutcomes( vector <string> board ) {
	h = SZ(board);
	
	LL res = 1;
	REP(i, SZ(board[0])){
		b.clear(); p.clear();
		MSET(dp, -1);
		REP(j, h){
			if(board[j][i] == 'U') b.PB(0), p.PB(j+1);
			if(board[j][i] == 'D') b.PB(1), p.PB(j+1);
		}
		mul(res, rec(0, 0));
	}
	vector <int> get2(int AminusB, int BminusC, int AplusB, int BplusC) {
		//if((AminusB+AplusB)%2==1) return VI();
		//if((BminusC+BplusC)%2==1) return VI();
		int A=(AminusB + AplusB)/2;
		int B=(BplusC+BplusC)/2;
		int C=BplusC-B;
		VI ans;
		if(A+B!=AplusB) return ans;
		ans.PB(A);
		ans.PB(B);
		ans.PB(C);
		return ans;
	}
Example #9
0
	REP(i, N){
		ad[i][0] = d[i];
		aw[i][0] = w[i];
		ae[i][0] = e[i];
		as[i][0] = s[i];
		D.PB(d[i]);
		for(int j = 1; j < n[i]; j++){
			ad[i][j] = ad[i][j-1] + dd[i];
			aw[i][j] = aw[i][j-1] + dp[i];
			ae[i][j] = ae[i][j-1] + dp[i];
			as[i][j] = as[i][j-1] + ds[i];
			D.PB(ad[i][j]);
		}
	}
Example #10
0
int main()
{
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	int n;cin>>n;
	VI even;
	VI odd;
	REP(i,n) {
		int t;cin>>t;
		if(t&1) odd.PB(i);
		else even.PB(i);
	}
Example #11
0
 vector<int> twoSum(vector<int>& nums, int target) {
     VI ans;
     for(VI::iterator i=nums.begin(); i != nums.end();++i){
         // index start with one instead zero, so it can be a condition
         if (dict[target - *i]){
             ans.PB(dict[target - *i]);
             ans.PB(i - nums.begin() + 1);
             return ans;
         }
         // put assignment last prevent that two same number, like 3+3=6
         // it will overwrite origin key-value
         dict[*i] = (i - nums.begin()) + 1;
     }
     return ans;
 }
void push_sp(int x, int y, VI &tp)
{
    while(y>=0 and y!=x)
    {
        tp.PB(y+1); y = sP[x][y];
    }
}
Example #13
0
int main()
{
    int n;
    while(cin>>n)
    {
        VI ar;
        int k;
//        fill(pr,0);
        for( int i=0; i<n; i++ )
        {
            cin>>k;
            ar.PB(k);
        }
        sort(ar.begin(),ar.end());
        int val=0;
        for( int i=ar.size()-1; i>=0; i-- )
        {
            //debug(i);
            val+=ar[i];
            //debug(val);
            int sum=0;
            for( int j=0; j<i; j++ )
            {
                sum+=ar[j];
               // debug(sum);
            }
            if( sum < val ) {cout<<n-i<<endl;break;}
        }
    }
    return 0;
}
Example #14
0
int main()
{
    int N = SI;
    int cnt = 0, neg = 0;
    VI v;
    REP(i,N)
    {
        int x = SI;
        if(x < 0)
        {
            ++neg;

            if(neg == 3)
            {
                v.PB(cnt);
                cnt = 0;
                neg = 1;
            }
        }
        else
        {
        }

        ++cnt;
    }
Example #15
0
int main()
{
	int T = SI, Q = SI, N = SI;

	VI tid;
	vector<double> tx, ty;
	REP(i,T) { tid.PB(SI); tx.PB(SLF); ty.PB(SLF); }
int main()
{
   int n,m; si(n); si(m);
   for(int i = 0; i<n; i++)
   {
      cin>>L[i]>>C[i];
   }
   while(m--){int x,y; si(x); si(y); x--; y--; E[x].PB(y); deg[y]++;}
   int x,src,dest; 
   si(src); 
   si(x); 
   si(dest);
   src--; dest--; C[src]+=x;
   VI tord;
   queue<int> Q; for(int i=0; i<n; i++) if(!deg[i])Q.push(i);
   while(!Q.empty()){ int x = Q.front(); Q.pop(); tord.PB(x); for(auto y : E[x]){deg[y]--; if(!deg[y]) Q.push(y);}}
   for(auto x : tord)
   {
      if(C[x]<=L[x])continue;
      double td = C[x]-L[x]; C[x] = L[x];
      if(!E[x].empty())
      {
         td /= (E[x].size());
         for(auto y : E[x])
            C[y]+=td;
      }
   }
   printf("%.7lf\n",C[dest]);
   return 0;	
}
Example #17
0
inline int solve(int testnum)
{
    int n; scanf("%d",&n);
    VI a; a.clear();
    REP(i,n) {
        int v; scanf("%d",&v);
        a.PB(v);
    }
Example #18
0
void dfs(int u) {
    vs[u] = 1;
    for(int i=0; i<SZ(g[u]); i++) {
        int w = g[u][i];
        if(!vs[w]) dfs(w);
    }
    v.PB(u);
}
Example #19
0
void DFS(int i) {

	if(!Visited[i]) {
		Visited[i] = 1;
		int size = Graph[i].size();
		REP(j,size) if(!Visited[Graph[i][j]]) DFS(Graph[i][j]);
		Topological.PB(i);
	}
Example #20
0
void dfs1(int x) {
	was[x] = true;
	REPS(i, e[x]) if (!was[e[x][i]]) {
		c[x][i] = false;
		dfs1(e[x][i]);
	}
	q.PB(x);
}
Example #21
0
int main()
{
	int N = SI, B = SI, A = SI;
	VI v;
	REP(i,N)
	{
		v.PB(SI);
	}
Example #22
0
int main()
{
    FastIO(); 
    string str;
    vector <string> v;
    VI vec;
    char c;
    int i,l,j=0,n;
    while(getline(cin,str))
    {
        v.PB(str);
        l=str.length();
        c=' ';
        for(i=0;i<l;i++)
        {
            if(str[i]!=' ')
            {
                c=str[i];
                break;
            }
        }
        if(c=='#'&&l!=0)
            vec.PB(1);
        else
            vec.PB(0);
    }
    n=v.size();
    for(i=0;i<n;i++)
    {
        if(vec[i])
            cout <<v[i]<<"\n";
        else
        {
            l=v[i].size();
            for(j=0;j<l;j++)
                if(v[i][j]!=' ')
                    cout <<v[i][j];
            if(i!=(n-1)&&vec[i+1]==1)
                cout <<"\n";
        }
    }
    if(vec[n-1]==0)
        cout <<"\n";
    return 0;
}
Example #23
0
string run(VI x, VI y){
  X = x; Y = y;
  N = x.size();

  REP(i, N) INDEX.PB(i);
  sort(ALL(INDEX), cmp);

  return dfs(0, 0, 0) ? "OK" : "NO";
}
Example #24
0
int dfs(int v){
    used[v] =1;
    for(int i=0;i<G[v].size();i++){
        if(!used[G[v][i]] ){dfs(G[v][i]);}
    }
    rec.PB(v);

    return 0;
}
Example #25
0
   int cellsLeft( vector <int> parent, int deletedCell ) {
	d = deletedCell;
	p = parent;
	VI l;
	REP(i, SZ(p)){
		bool le = true;
		REP(j, SZ(p)) if(p[j] == i) le = false;
		if(le) l.PB(i);
	}
void DFS(){
    visited.resize(k,0);
    REP(v,k) if (!visited[v]){
        visited[v] = 1;
        printf("%d 0\n",v+1);
        stack.PB(v);
        while (!(stack.empty())){
            int u = stack.back();
            stack.pop_back();
            for(auto ngb : sol[u])
                if (!visited[ngb]){
                    visited[ngb] = 1;
                    printf("%d %d\n",ngb+1,u+1);
                    stack.PB(ngb);
                }
        }    
    }
}
Example #27
0
   int getMoves( vector <string> board, int R, int C ) {
	   r = R; c = C;
	   szr = SZ(board); szc = SZ(board[0]);
	   B.clear();
	   REP(i, szr){
		   int tmp = 0;
		   REP(j, szc) if(board[i][j] == 'X') tmp += (1<<j);
		   B.PB(tmp);
	   }
Example #28
0
int main(){
	int n;
	scanf("%d",&n);
	VI p;
	REP(i,n){
		int a;
		scanf("%d",&a);
		p.PB(a);
	}
Example #29
0
inline void go(int v)
{
	if(mark[v]) return;
	mark[v] = 1;
	for(auto &j : g[v]) {
		if(mark[j]) continue;
		go(j);
	}
	res.PB(v);
}
Example #30
0
int main(){
	int n;
	si(n);
	for(int i=0;i<n;i++) si(a[i]);
	int sum = 0,cnt = 0;
	for(int i=0;i<n;i++){
		if(a[i]<=0){
			if(sum) v.PB(sum);
		   	v.PB(a[i]);
			sum = 0;
		}
		else{
			sum += a[i];
		}
	}
	if(sum) v.PB(sum);
	for(int i=0;i<SZ(v);i++) cout<<v[i]<<' '; cout<<endl;
	return 0;
}