玲珑杯 J -- Just for Fun

来源:互联网 发布:python中文乱码 编辑:程序博客网 时间:2024/06/04 20:10
J -- Just for Fun

Time Limit:1s Memory Limit:64MByte

Submissions:970Solved:75

DESCRIPTION

P=NP?

INPUT
First line contains a single integer T which denotes the number of test cases. For each test case, there is two numbers which denote N and P separated by a space.(0<=N<231231,0<=P<231231)The input data is no large than 1M.
OUTPUT
For each case, output the "Y" or "N" in a single line.
SAMPLE INPUT
21 123123 0
SAMPLE OUTPUT
YY
SOLUTION
玲珑杯”ACM比赛 Round #5
本是水题,奈何坑死一群人,其实看仔细点就能发现坑点,因为题目没有说是整数,而且长度不定,有可能是0000.0000000或者0000001.000000000000,所以有人用Long long和long double存,其实都是存不下的。只能用大数模拟,所以只要判断前面的数为1或后面的数为0就AC了。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define mem(p,k) memset(p,k,sizeof(p))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define inf 0x5fffffff#define LL long longusing namespace std;char n[5000000],p[5000000];int main(){    int t;    cin>>t;    while(t--){        scanf("%s%s",&n,&p);//cout<<n<<p<<endl;        int cur=0,cur2=0;        for(int i=0;i<strlen(n);i++){            if(n[i]=='.'){                    for(int j=i+1;j<strlen(n);j++){                        if(n[j]!=48){                                cur=1;break;                        }                    }                    break;            }            else if(n[i]=='1'){                    cur2=1;                    if(i!=strlen(n)-1&&n[i+1]!='.'){                        cur=1;break;                    }            }            else if(n[i]!=48){//cout<<"asd"<<endl;                    cur=1;break;            }        }//cout<<cur<<endl;        if(!cur&&cur2==1){            cout<<"Y"<<endl;continue;        }        cur=1;        for(int i=0;i<strlen(p);i++){                if(p[i]!='.'&&p[i]!=48){                    cur=0;break;                }//cout<<"asd"<<endl;        }        if(!cur)cout<<"N"<<endl;        else cout<<"Y"<<endl;    }    return 0;}


0 0
原创粉丝点击