Ciel and Dancing

题目大致意思是在一个房间里面有n个男孩和m个女孩一起跳舞,然后每首歌能跳一次,男女搭配跳舞时至少有一个人没有和任何人跳过。 然后问你能跳几首歌。输入的是男孩和女孩的人数,输出第一行为最多跳的歌曲数k,接下来的k行为男女跳舞的顺序(男女生用1到n,m编号表示)
A. Ciel and Dancing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:

  • either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before);
  • or the girl in the dancing pair must dance for the first time.

Help Fox Ciel to make a schedule that they can dance as many songs as possible.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room.

Output

In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m.

Sample test(s)
input
2 1
output
2
1 1
2 1
input
2 2
output
3
1 1
1 2
2 2
Note

In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).

And in test case 2, we have 2 boys with 2 girls, the answer is 3.

这个题其实很简单的,但是挖了个很大很大的坑!坑死我了!!我比赛时写到一半时发现好几种情况都满足题目的意思,输出时也是按样例输出,我又返回研究题目无果,然后就狠心把女孩和第一个男孩全部跳一次,然后剩下最后一个女孩,再和其他男孩跳舞。。然后提交,竟然一次过了!!!!!(PS:坑爹啊!晚上11点30开始,到凌晨1点30结束,校园网断网了,用的CMCC,然后再12点一刻的时候CMCC突然没有信号了,到了1点才恢复。然后只提交了一道题。。)

AC的代码:

#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
    int n,m,i,j,song,x;
    int boy[110],girl[110];
    while(scanf("%d%d",&n,&m) != EOF)
    {
        for(i = 0; i < 110; i++)
        {
            boy[i] = girl[i] = 0;
        }
        if(n >= m)
        {
            printf("%d\n",m+n-1);
        }
        else
        {
            printf("%d\n",n+m-1);
        }
        for(i = 1; i <= n; i++)
        {
            if(girl[m] != 1)
            {
                for(j = 1; j <= m; j++)
                {
                    printf("%d %d\n",i,j);
                    boy[i] = 1;
                    girl[j] = 1;
                }
            }
            else
            {
                printf("%d %d\n",i,m);
            }
        }
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值