• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Codeforces 417 C

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

 Status

Description

One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into nteams and played several matches, two teams could not play against each other more than once.

The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.

Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly ktimes. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ nai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 ton.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Sample Input

Input
3 1
Output
3
1 2
2 3
3 1

Source

很久之前做的题,输出所有的情况就行了。
#include <iostream>
#include <stdio.h>
typedef long long LL;
using namespace std;
int main()
{
    int i,n,m,k,j;
    cin>>n>>k;
    if (n-1<2*k)
    cout<<-1<<endl;
    else
    {
        cout<<n*k<<endl;
        for (i=1;i<=n;i++)
        {
            for (j=0;j<k;j++)
            printf("%d %d\n",i,(i+j)%n+1);
        }
    }
    return 0;
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++Traps&amp;Pitfalls发布时间:2022-07-13
下一篇:
【原创】开源Math.NET基础数学类库使用(08)C#进行数值积分发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap