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

注意整数常量要加LL

Posted by algoriiiiithm at 2021-12-10 11:46:42 on Problem 3685
因为poj的编译器版本问题,整数常量末尾不加LL就会出问题.最要命的是不加LL的wa代码在本地调试找了网上的AC代码对拍了几万个都找不出问题,晕死。
本来还以为数据范围有问题所以要扩大上下界(我练习的时候有强迫症,不管数组范围还是二分查找范围都喜欢一分不差)
建议以后在poj交题遇到见鬼的wa情况 可以g++ solution.cpp -std=c++98看看会不会报warning
AC代码:(297ms 二分法+二次方程求根公式)
/*solution to POJ-3685:Matrix*/
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int N;
long long M;

bool P(long long x);

int main(void)
{
	int T;
	scanf("%d", &T);
	while(T--){
		long long L, R;
		scanf("%d%lld", &N, &M);
		L = -2499849999LL; R = 7500000000LL; //就这个地方常量不加LL就wa
		while(L < R){
			long long mid = floor((L + R) / 2.0);
			if(P(mid))
				R = mid;
			else
				L = mid + 1;
		}
		printf("%lld\n", L);
	}
	return 0;
}

// P(x): 存在M个元素 <= x
bool P(long long x)
{
	long long cnt = 0;
	for(int j = 1; j <= N; j++){
		long long delta = -3*j*(long long)j + 600000*(long long)j + 4*x + 10000000000;
		double s;
		if(delta < 0)
			continue;
		s = (-100000 - j + sqrt((double)delta)) / 2;
		if(s < 1)
			continue;
		cnt += min((double)N, floor(s));
	}
	return cnt >= M;
}
// 二分法/数学

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