坑点:0特判

View Code
const double esp=1e-11;
string ElectionFraudDiv2::IsFraudulent(vector <int> percentages) {
    vector <double> sb ;
    double sum=0;
    for (int i = 0 ; i < percentages.size() ; i++)
    {
        sum+=percentages[i]+0.0;
        sb.push_back(percentages[i]+0.0);
    }
    double sum1,sum2;
    sum1=sum+percentages.size()*0.5;
    sum2=sum;
    for (int i = 0 ; i < percentages.size() ; i++)
    {
        if(sb[i]+esp>0.0&&sb[i]-esp<0.0)
            continue;
        sum2-=0.5;
    }
    if((sum1+esp>100.0&&sum1-esp<100.0))
        return "YES";
    if((sum1>100.0&&sum2<100.0)||(sum2+esp>100.0&&sum2-esp<100.0))
        return "NO";
    return "YES";
}