1. 程式人生 > >hihocoder hiho一下 第九十五週

hihocoder hiho一下 第九十五週

先挖個坑

我看完這道題第一感覺是不用拓展歐幾里得,直接每走一步迴圈一次就行了,迴圈一個很大的次數(比如9999999,不會超時的次數),要是能找到就能找到了,找不到就找不到了。(小技巧:用這行程式碼就可以取消iostream的同步繫結,可以讓cin 的輸入速度和scanf一樣快)

std::ios::sync_with_stdio(false);

下面程式碼在本地能執行成功,答案也對,但是提交上去就出現runtime error,程式碼也不多,哪位大神有時間可以幫我看一下。蟹蟹

#include <stdio.h>
#include <iostream>

using namespace std;
int s1,s2,v1,v2,m;
int i = 999999;
bool go(){
    if(s1+v1>m-1)
        s1 = s1+v1-(m-1);
    else
        s1 += v1;
    if(s2+v2>m-1)
        s2 = s2+ v2 - (m-1);
    else
        s2 += v2;
    if(s1 == s2)
    {
        printf("%d",999999-i+1);
        return true;
    }
    return  false;

}

int main()
{
    std::ios::sync_with_stdio(false);
    cin >> s1 >> s2 >> v1 >> v2 >> m;
    while(i -- )
    {
        if(go()) return 1;

    }
    printf("-1");
    return -1;
}