Ejemplo n.º 1
0
int main()
{
  int t,i,j,k,n,s,m;
  scanf("%d",&t);
  pii p;
  
  while(t--){
    v.clear();
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d %d",&j,&k);
      v.push_back(ii(j,0));
      v.push_back(ii(k,1));      
    }

    sort(v.begin(),v.begin()+2*n);
    s=0,m=-SENTINEL;
    for(i=0;i<2*n;i++){
      p=v[i];
      if(p.second==0)s+=1;
      else s-=1;
      m=max(m,s);
    }
    printf("%d\n",m);
  }
  return 0;
}
void factor(ll n,int id)
{
    for(int i=0;prime[i]<=sqrt(n) and i<SZ(prime);i++)
    {
        if(n%prime[i]==0)
        {
            int cnt=0;
            while(n%prime[i]==0)
            {
                cnt++;
                n/=prime[i];
            }
            if(id==2){v.pb(mp(prime[i],cnt));lprime++;}
            else if(id==0) {a1[prime[i]]=cnt;aprime++;}
            else if(id==1) {b1[prime[i]]=cnt;bprime++;}
        }
    }

    if(n>1)
    {
        if(id==2){v.pb(mp(n,1));lprime++;}
        else if(id==0) {a1[n]=1;aprime++;}
        else if(id==1) {b1[n]=1;bprime++;}
    }
}
Ejemplo n.º 3
0
int removeDishes(const vpii &pairs) {
  bool removedDish[n];
  bool removedPair[pairs.size()];
  fill(removedDish, removedDish+n, false);
  fill(removedPair, removedPair+pairs.size(), false);
  int count = 0;
  while (true) {
    int pairIndex = findRemovablePair(pairs, removedDish, removedPair);
    if (pairIndex < 0) {
      return count;
    }
    removedPair[pairIndex] = true;
    removedDish[pairs[pairIndex].first] = true;
    removedDish[pairs[pairIndex].second] = true;
    count += 2;
  }
}
Ejemplo n.º 4
0
bool findMatch(int v, int* prev, bool* visit, int hSize, const vpii& pairs) {
  if (v < 0) {
    return true;
  }
  for (int i = 0; i < hSize; i++) {
    if (visit[i] ||
        !binary_search(pairs.begin(), pairs.end(), make_pair(i, v))) {
      continue;
    }
    visit[i] = true;
    if (findMatch(prev[i], prev, visit, hSize, pairs)) {
      prev[i] = v;
      return true;
    }
  }
  return false;
}
Ejemplo n.º 5
0
int findRemovablePair(const vpii &pairs, const bool* removedDish,
    const bool* removedPair) {
  for (int i = 0; i < pairs.size(); i++) {
    if (!removedPair[i] && removableDish(pairs[i].first, removedDish) &&
        removableDish(pairs[i].second, removedDish)) {
      return i;
    }
  }
  return -1;
}
Ejemplo n.º 6
0
int generatePairsDfs(vpii &pairs) {
  int index = findFirstNonAssignedIndex();
  if (index >= 0) {
    int result = 0;
    for (int i = index+1; i < n; i++) {
      if (!assigned[i] && colors[index] == colors[i]) {
        assigned[i] = true;
        assigned[index] = true;
        pairs.push_back(make_pair(index, i));
        result = max(result, generatePairsDfs(pairs));
        assigned[i] = false;
        assigned[index] = false;
        pairs.pop_back();
      }
    }
    return result;
  } else {
    return removeDishes(pairs);
  }
}
ll dijkstra(int s, int t){
	found.assign(N,0); dist.assign(N,INF); f.assign(N,0); dad.assign(N,pii(-1,2));
	dist[s]=0; f[s]=INF;
	while(s!=-1){
		int best=-1; found[s]=true;
		for(int k=0 ; k<N; k++){
			if(found[k]) continue;
			relax(s,k,cap[s][k]-flow[s][k],cost[s][k],1);
			relax(s,k,flow[k][s],-1*cost[k][s],-1);
			if(best==-1 || dist[k]<dist[best]) best=k;
		}
		s=best;
	}
	for(int k=0 ; k<N ; k++){
		pi[k]=min(pi[k]+dist[k],INF);
	}
	return f[t];
}
Ejemplo n.º 8
0
 void dfs(vvi& res, vi& cur, vpii& count, int idx) {
     string ident(idx * 4, ' ');
     if (idx == count.size()) {
         res.push_back(cur);
         return;
     }
     pii& p = count[idx];
     int num = p.first, cnt = p.second;
     for (int rep = 0; rep <= cnt; ++rep) {
         for (int i = 0; i < rep; ++i) {
             cur.push_back(num);
         }
         dfs(res, cur, count, idx + 1);
         for (int i = 0; i < rep; ++i) {
             cur.pop_back();
         }
     }
 }
int main()
{
    sive();
    int cas=0,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld %lld %lld",&a,&b,&l);
        v.clear();
        mem(a1,0);mem(b1,0);

        aprime=0;bprime=0;lprime=0;
        factor(a,0);
        factor(b,1);
        factor(l,2);

        ll ans=make();
        if(ans==-1) printf("Case %d: impossible\n",++cas);
        else printf("Case %d: %d\n",++cas,ans);
    }
    return 0;
}
Ejemplo n.º 10
0
Archivo: b.cpp Proyecto: alexkats/Code
int main ()
{
    srand (time (0));

    //freopen (NAME".in", "r", stdin);
    //freopen (NAME".out", "w", stdout);

    scanf ("%d %d", &n, &k);

    for (int i = 0; i < n; i++)
    {
        int x;
        scanf ("%d", &x);
        a.pb (mp (x, i + 1));
    }

    sort (a.begin (), a.end (), cmp);
    int curr = a [n - 1].frs - a [0].frs;

    while (curr > 1 && k > 0)
    {
        a [n - 1].frs--;
        a [0].frs++;
        ans.pb (mp (a [n - 1].snd, a [0].snd));
        k--;
        sort (a.begin (), a.end (), cmp);
        curr = a [n - 1].frs - a [0].frs;
    }

    printf ("%d %d\n", curr, (int) ans.size ());

    for (int i = 0; i < (int) ans.size (); i++)
        printf ("%d %d\n", ans [i].frs, ans [i].snd);

    return 0;
}