提交记录 2089


用户 题目 状态 得分 用时 内存 语言 代码长度
negiizhao 1003. 测测你的二分查找 Accepted 100 66.11 us 12 KB C 925 B
提交时间 评测时间
2018-06-21 17:59:38 2020-07-31 20:58:43
const int block_cnt = 16;

int guide[16];

#define g(i) guide[(i)] = a[n / block_cnt * (i)]
#define g0(i) g(i), g(i + 1)
#define g1(i) g0(i), g0(i + 2)
#define g2(i) g1(i), g1(i + 4)
#define g3(i) g2(i), g2(i + 8)

int init(const unsigned *a, const int n)
{
	g3(0);
	return 0;
}

#define w(i) p = a + n / block_cnt * (i), n = n / block_cnt * ((i) + 1) - n / block_cnt * (i) - 1;
#define c(i, a, b) if (x < guide[(i)]) a else b
#define c0(i) c((i), w((i) - 1), w((i)))
#define c1(i) c((i), c0((i) - 1), c0((i) + 1))
#define c2(i) c((i), c1((i) - 2), c1((i) + 2))
#define c3(i) c((i), c2((i) - 4), c2((i) + 4))

int binary_search(const unsigned *a, int n, const unsigned x)
{
	static int _ = 1;
	if (_)
		init(a, n), _ = 0;
	
	const unsigned *p;
	
	c3(8);
	
	int mid;
	--n;
	while (p[n] != x)
		if (mid = (n * (double)(x - *p) / (p[n] - *p)), p[mid] < x)
			p += mid + 1, n -= mid + 1;
		else
			n = mid;
	
	return p - a + n;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #166.11 us12 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-24 03:10:01 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠