示例#1
0
文件: b.cpp 项目: 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;
}
示例#2
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;
}