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;
}
复制代码

 

posted @   人艰不拆_zmc  阅读(199)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示