为什么错了一个点?

我的程序是根据魔法值数量和剩余时间距离来计算是否积攒魔法的:
c++
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<stdio.h>
#include<algorithm>
using namespace std;
int disleft[10]={119,119,51,51,51,51,34,34,34,34};
int timeleft[10]={7,7,3,3,3,3,2,2,2,2};
int usemagic[10]={2,2,1,1,1,1,1,1,1,1};
long long m,s,t,dis=0,time=0;
int main()
{
//freopen("escape.in","r",stdin);
//f/reopen("escape.out","w",stdout);

cin>>m>>s>>t;
while(m>=10)
{
m=m-10;
dis=dis+60;time++;
if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;}
if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;}
}
while(time<t)
{
if(s-dis>disleft[m] && t-time>timeleft[m])
{
int m2=m;
dis=dis+usemagic[m2]*60;
time=time+timeleft[m2];
m=m+(timeleft[m2]-usemagic[m2])*4-usemagic[m2]*10;
if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;}
else if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;}
}
else
{
int tt=timeleft[m];
while(tt>0)
{
tt=tt-1;
dis=dis+17;
time=time+1;
if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;}
else if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;}
}
}
}
cout<<"No"<<endl;cout<<dis<<endl;

fclose(stdin);fclose(stdout);
}
```

2 条评论

  • @ 2016-10-26 14:01:13

    s-dis>=disleft[m] && t-time>=timeleft[m]

  • @ 2016-10-26 14:00:03
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    int disleft[10]={119,119,51,51,51,51,34,34,34,34};
    int timeleft[10]={7,7,3,3,3,3,2,2,2,2};
    int usemagic[10]={2,2,1,1,1,1,1,1,1,1};
    long long m,s,t,dis=0,time=0;
    int main()
    {
        //freopen("escape.in","r",stdin);
        //f/reopen("escape.out","w",stdout);
        
        cin>>m>>s>>t;
        while(m>=10)
        {
            m=m-10;
            dis=dis+60;time++;
            if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;}
            if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;}
        }
        while(time<t)
        {
            if(s-dis>=disleft[m] && t-time>=timeleft[m])
            {
                int m2=m;
                dis=dis+usemagic[m2]*60;
                time=time+timeleft[m2];
                m=m+(timeleft[m2]-usemagic[m2])*4-usemagic[m2]*10;
                if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;}
                else if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;}
            }
            else
            {
                int tt=timeleft[m];
                while(tt>0)
                {
                    tt=tt-1;
                    dis=dis+17;
                    time=time+1;
                    if(time>=t && dis<s){cout<<"No"<<endl;cout<<dis<<endl;return 0;}
                    else if(dis>=s && time<=t){cout<<"Yes"<<endl;cout<<time<<endl;return 0;}
                }
            }
        }
        cout<<"No"<<endl;cout<<dis<<endl;
        
        fclose(stdin);fclose(stdout);
    }
    

    我知之矣

  • 1

信息

ID
1431
难度
5
分类
动态规划 | 背包 点击显示
标签
递交数
6110
已通过
1899
通过率
31%
被复制
14
上传者