codeforces 322 A Ciel and Dancing

简介: 有n个男孩和m个女孩,他们要结对跳舞,每对要有一个女孩和一个男孩,而且其中一个要求之前没有和其他人结对,求出最大可以结多少对。

题意:

     有n个男孩和m个女孩,他们要结对跳舞,每对要有一个女孩和一个男孩,而且其中一个要求之前没有和其他人结对,求出最大可以结多少对。


如图,一条线代表一对,只有这样三种情况。

#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        int mn = min(n, m);
        int k = (mn<<1) - 1;
        k += (max(n, m) - mn);
        int a = 1, b = 1;
        cout << k << endl;
        int i = 1;
        int t= 0;
        for (; i < mn; i++)
        {
            printf("%d %d\n", i, i);
            printf("%d %d\n", i, i+1);
            t = i;
        }
        t++;
        for (;i <= max(n, m); i++)
        {
            if (n <= m)
            printf("%d %d\n", t, i);
            else
                printf("%d %d\n", i, t);
        }
    }
    return 0;
}
目录
相关文章
|
6月前
codeforces 312
A. Whose sentence is it?
26 0
|
6月前
codeforces 304A. Pythagorean Theorem II
给你一个n,计算出1 ≤ a ≤ b ≤ c ≤ n.使得由abc构成的三角形满足勾股定理,c为斜边。 没有简单的方法,直接爆力,但是要注意,有些abc满足勾股定理的表达式,但不一定是三角形,所以要判断一下,根据三角形三边的性质,两边之和大于第三边,两边之差小于第三边。
31 0
|
机器学习/深度学习 人工智能 网络架构
Codeforces 706B Interesting drink
B. Interesting drink time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard outp...
1137 0
|
人工智能
Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard ...
1133 0
Codeforces 591B Rebranding
B. Rebranding time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output ...
829 0
|
人工智能
Codeforces 719B Anatoly and Cockroaches
B. Anatoly and Cockroaches time limit per test:1 second memory limit per test:256 megabytes input:standard input output:stan...
862 0