hdoj 1276 士兵队列训练问题(强行用下链表)

该博客介绍了一种解决hdoj 1276题目的思路,通过链表来简化复杂度。文章指出,理解题目中关于报数结束后的队伍人数关键,然后提供了相应的代码实现。
摘要由CSDN通过智能技术生成

思路如下:题目很好理解(但是有坑,在报数报完一轮的时候才看队伍里有几个人);用链表来写思路会简单很多;

代码如下:

#include<bits/stdc++.h>
using namespace std;
struct node
{
    int i;
    node *next;
};
void del(node *a,node *b)
{
    node *temp;
    temp=a->next;
    cout<<temp->i;
    free(temp);
    a->next=b;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<"1"<<endl;
            continue;
        }
        else if(n==2)
        {
            cout<<"1"<<" "<<"2"<<endl;
            continue;
        }
        else if(n==3)
        {
            cout<<"1"<<" "<<"2"<<" "<<"3"<<endl;
            continue;
        }
        node *head,*p;
        p&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值