Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

暴力0ms,不能用double,wa到疯

Posted by cxlm at 2018-03-09 23:07:17 on Problem 3100
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    int numb, numn;
    cin >> numb >> numn;
    while(numb != 0 && numn != 0) {
        int cha1, cha2;
        int res = 1, temp1 = pow(double(res), numn), temp2;
        while(true) {
            cha1 = numb - temp1;
            cha1 = cha1 < 0 ? (-cha1) : cha1;
            temp2 = pow(double(res + 1), numn);
            cha2 = numb - temp2;
            cha2 = cha2 < 0 ? (-cha2) : cha2;
            if(cha1 > cha2) {
                temp1 = temp2;
            } else {
                break;
            }
            res++;
        }
        cout << res << endl;
        cin >> numb >> numn;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator