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

百思不得其解~为什么longlong就TLE,改成__int64就能过呢? 附代码

Posted by cn_chen at 2008-09-06 23:45:09 on Problem 3685
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
const ll w=100000;

int main() {
    int tc;
    scanf("%d",&tc);
    while(tc--) {
        ll n,m;
        scanf("%lld%lld",&n,&m);
        ll max=w*w*10;
        ll min=-max;
        while(min<max) {
            ll x = (min+max)/2;
            if(x==max) x--;
            ll sum = 0;
            for(ll j = 1; j <= n && sum<=m; ++j) {
                ll det = (w+j)*(w+j) - 4*(j*j-w*j-x);
                if(det>=0) {
					ll q = int(sqrt(det));
					if((q+1)*(q+1) <= det) q++;
                    ll x0 = (-(w+j)-q)/2;
                    ll x1 = (-(w+j)+q)/2;
                    if(x0<1) x0=1;
                    if(x1>n) x1=n;
                    if(x0<=x1) sum+=(x1-x0+1);
                }
            }
            if(sum<m) min=x+1;
            else max=x;
        }
        printf("%lld\n",min);
    }
    return 0;
}



以下是int64
#include <iostream>
#include <cmath>
#define ll __int64
using namespace std;
const ll w=100000;

int main() {
    int tc;
    scanf("%d",&tc);
    while(tc--) {
        ll n,m;
        scanf("%I64d%I64d",&n,&m);
        ll max=w*w*10;
        ll min=-max;
        while(min<max) {
            ll x = (min+max)/2;
            if(x==max) x--;
            ll sum = 0;
            for(ll j = 1; j <= n && sum<=m; ++j) {
                ll det = (w+j)*(w+j) - 4*(j*j-w*j-x);
                if(det>=0) {
					ll q = int(sqrt(det));
					if((q+1)*(q+1) <= det) q++;
                    ll x0 = (-(w+j)-q)/2;
                    ll x1 = (-(w+j)+q)/2;
                    if(x0<1) x0=1;
                    if(x1>n) x1=n;
                    if(x0<=x1) sum+=(x1-x0+1);
                }
            }
            if(sum<m) min=x+1;
            else max=x;
        }
        printf("%I64d\n",min);
    }
    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