求助 60pts WA
查看原帖
求助 60pts WA
574944
Micnation_AFO楼主2022/8/21 06:52

rt,思路是执行五万次题目中给的代码,然后取最小值,不知道为什么 WA 了:

#include <iostream>
#include <map>

using namespace std;

const int N = 1100010;

int n, q;
int a[N];
map<int, int> m;
bool flag;

int find(int *num,int x,int len)
{
	int l=1,r=len,mid,cnt=0,w;
	while(l<r)
	{
		cnt++;
		w=rand()%2;
		mid=(l+r+w)/2;
		if(num[mid]-w<x) l=mid+!w;
		else r=mid-w;
	}
	return cnt;
}

int find(int i) {
	int ans = 1e9;
	for (int j = 1; j <= 50000; j++) {
		ans = min(ans, find(a, i, n));
	}
	return ans;
}

void bf() {
	for (int i = 1; i <= n; i++) cin >> a[i];
	int q; cin >> q;
	for (int i = 1; i <= q; i++) {
		int x;
		cin >> x;
		cout << find(x) << endl;
	}
}

int main() {
    scanf("%d", &n);
    if (1) {
        bf();
        return 0;
    }
    
    for (int i = 1; i <= n; i++) scanf("%d", a + i), m[a[i]] = i;
    int x = 1, sum = 0, cnt = 0;
    while (1) {
        if (sum + x >= n) break;
        sum += x;
        x *= 2, cnt++;
    }
    cout << sum << " " << x << " " << cnt << endl;
    if (n - sum >= x / 2) flag = true;
    else flag = false;
    scanf("%d", &q);
    while (q--) {
        int x; scanf("%d", &x);
        if (!flag) cout << cnt << endl;
        else cout << ((m[x] % 2) ? cnt : cnt + 1) << endl; 
    }
    return 0;
}

https://www.luogu.com.cn/record/84612468

2022/8/21 06:52
加载中...