CodeForces 416A

来源:互联网 发布:hottoys淘宝店哪些靠谱 编辑:程序博客网 时间:2024/05/17 05:03

这道题,有两个错误。一个是:没有测试负数的情况;另一个也是核心错误就是MAX不应该定义成 2000000001 而应该定义成 2000000000,最后取余的时候可以用(MAX + 1)。

Wa:

#include<iostream>#include<cstdio>#include<cstring>#include<string>using namespace std;#define MAX 2000000001int nasce,num,length,Max,Min;string ope;char ans;int main(){    while(scanf("%d",&nasce) != EOF)    {        Min = -MAX;        Max = MAX;        while(nasce--)        {            cin >> ope >> num >> ans;            if(ans == 'Y')            {                if(ope == ">")                    Min = max(++num,Min);                else                    if(ope == "<")                        Max = min(--num,Max);                    else                        if(ope == ">=")                            Min = max(num,Min);                        else                            if(ope == "<=")                                Max = min(num,Max);            }            else            {                if(ope == ">")                    Max = min(num,Max);                else                    if(ope == "<")                        Min = max(num,Min);                    else                        if(ope == ">=")                            Max = min(--num,Max);                        else                            if(ope == "<=")                                Min = max(++num,Min);            }        }        //cout << Min << ' ' << Max << ' ' << num << endl;        if(Max >= Min)            cout << Min % MAX<< endl;        else            cout << "Impossible" << endl;    }    return 0;}

Ac:

#include<iostream>#include<cstdio>#include<cstring>#include<string>using namespace std;#define MAX 2000000000int nasce,num,length,Max,Min;string ope;char ans;int main(){    while(scanf("%d",&nasce) != EOF)    {        Min = -MAX;        Max = MAX;        while(nasce--)        {            cin >> ope >> num >> ans;            if(ans == 'Y')            {                if(ope == ">")                    Min = max(++num,Min);                else                    if(ope == "<")                        Max = min(--num,Max);                    else                        if(ope == ">=")                            Min = max(num,Min);                        else                            if(ope == "<=")                                Max = min(num,Max);            }            else            {                if(ope == ">")                    Max = min(num,Max);                else                    if(ope == "<")                        Min = max(num,Min);                    else                        if(ope == ">=")                            Max = min(--num,Max);                        else                            if(ope == "<=")                                Min = max(++num,Min);            }        }        //cout << Min << ' ' << Max << ' ' << num << endl;        if(Max >= Min)            cout << Min % (MAX + 1) << endl;        else            cout << "Impossible" << endl;    }    return 0;}



0 0