求 Hack 数据
查看原帖
求 Hack 数据
147999
Warriors_Cat楼主2020/5/4 11:28

昨天比赛的时候,这道题我的解法的复杂度是 O(klog2k+k+n3)O(k\log_2k+k+n^3) 的,但 std 代码是 O(k2+n3)O(k^2+n^3) 的,大概率是我写假了,我却 AC 了,有人能 Hack 掉吗qwq

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read(){
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ x = x * 10 + (ch ^ 48); ch = getchar(); }
	return x * f;
}
struct node{
	int t, v;
	bool operator < (const node&rhs)const{
		return t < rhs.t;
	}
}a[5010];
int n, m, K, mp[210][210], x, y, z, t[5010], v[5010], ans, idx, lst;
int main(){
	n = read(); m = read(); K = read(); memset(mp, 63, sizeof(mp));
	for(int i = 1; i <= m; ++i){
		x = read(); y = read(); z = read();
		mp[x][y] = min(mp[x][y], z);
		mp[y][x] = min(mp[y][x], z);
	}
	for(int i = 1; i <= n; ++i) mp[i][i] = 0;
	for(int k = 1; k <= n; ++k){
		for(int i = 1; i <= n; ++i){
			for(int j = 1; j <= n; ++j){
				mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
			}
		}
	}
	for(int i = 1; i <= K; ++i){
		a[i].t = read(); a[i].v = read();
	}
	sort(a + 1, a + K + 1); idx = 1, lst = 0;
	for(int i = 1; i <= K; ++i){
		if(a[i].t - lst >= mp[idx][a[i].v]){
			lst = a[i].t; idx = a[i].v; ans++;
		}
	}//这里跟 std 不一样,似乎是贪心,但我证明不了这个正确qaq
	printf("%d", ans); 
}
2020/5/4 11:28
加载中...