SDUT3165:Round Robina(循环链表)

题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=3165

题意分析:

比赛时这题没有A真伤心,错了11遍,最后发现题意少读了一句。

We note that E\'s count was irrelevant to the decision to end the game.

就是它丫的上面那句,比赛时真的是不能急着做题啊,一定要弄明白题在做,卡了三个小时就因为这个水逼题目。提供一组数据

4 5 输出时 3 1

代码如下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef struct node
{
    int fen;
    struct node *next;
} node;
int n,m;
int main()
{
    int cnt,sum,F,FF;
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        scanf("%d",&m);
        struct node *head,*tail,*p,*q;
        head=new node;
        head->fen=0;
        head->next=NULL;
        tail=head;
        for(int i=2; i<=n; i++)
        {
            p=new node;
            p->next=NULL;
            p->fen=0;
            tail->next=p;
            tail=p;
        }
        tail->next=head;
        for(q=head; q->next!=head;)
            q=q->next;
        sum=0;
        cnt=0;
        while(cnt<n-1)
        {
            p=q->next;
            p->fen++;
            sum++;
            if(sum%m==0)
            {
                sum-=m;
                F=q->fen;
                FF=p->next->fen;
                cnt++;
                if(F==FF)
                {
                    break;
                }
                q->next=p->next;
                p->next=NULL;
                delete(p);
            }
            else q=p;
        }
        n=n-cnt;
        printf("%d %d\n",n,F);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/zhangmingcheng/p/4350652.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值