其他分享
首页 > 其他分享> > cocktail with pony (模拟+写语句时的注意)

cocktail with pony (模拟+写语句时的注意)

作者:互联网

思路:没啥好说的,就是在转移的过程中有一个条件要特判一下

后记:

#include <bits/stdc++.h>
using namespace std;
#define  M 10005
#define ri register int

template <class G> void read(G &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return ;
}

int T;
int v1,v2,x1,x2,n;
int main(){
    
    
    read(T);
    while(T--)
    {
        read(n);read(v1);read(v2);read(x1);read(x2);
        if(x1<x2)
        {
            long long  ans=0;
            while(1)
            {
                if(x2+v2<=n) x2+=v2,ans++;
                else
                {
                    ans++;
                    if(x1==n-1)
                    {
                        printf("%lld\n",ans);
                        break;
                    }
                    int tmp=n-x2;
                    tmp=v2-tmp;
                    if(tmp&1) x2=n-1;
                    else x2=n;    
                }
                ans++;
                x1+=v1;
                if(x1>=x2)
                {
                    printf("%lld\n",ans);
                    break;
                }
            }
        }else 
        {
            long long  ans=0;
            while(1)
            {
                if(x2-v2>=1) x2-=v2,ans++;
                else
                {
                    ans++;
                    if(x1==2)
                    {
                        printf("%lld\n",ans);
                        break;
                    }
                    int tmp=x2-1;
                    tmp=v2-tmp;
                    if(tmp&1) x2=2;
                    else x2=1;    
                }
                ans++;
                x1-=v1;
                if(x1<=x2)
                {
                    printf("%lld\n",ans);
                    break;
                }
            }
        }
    }
    return 0;
    
    
    
}
View Code

 

标签:语句,tmp,ch,pony,cocktail,int,else,ans,x2
来源: https://www.cnblogs.com/Lamboofhome/p/16230191.html