la3716( 數學變形)

2021-07-29 06:59:50 字數 981 閱讀 7769

/*

translation:

給出兩條字串a,b。找出一段最長的子區間,使得區間所有位置x,有不超過p%的位置存在a[x]!=b[x]

solution:

利用數學變形

構造乙個數列,兩字串相等的位置為0,不等的為1。另sum[i]為字首和。則就是求

(sum[e]-sum[s])/(e-s)不超過p%的最長長度是多少?

note:

* 看上去跟la4726很像,但是方法不同。利用等式變形:(sum[r]-sum[l])/(r-l) <= p / 100

變為sum[r]∗100−r∗p≤sum[l]−l∗p.令val[i] = sum[i] * 100 - i * p;

若val[i]>=val[j] && i <= j的區間(i,j)才是合法區間。

*/#include #include #include #include using namespace std;

const int maxn = 150000 + 5;

int vec[maxn], n, p;

char a[maxn], b[maxn];

int sum[maxn];

bool hassolution;

struct node

node(){}

bool operator < (const node& rhs) const

} nodes[maxn];

int main()

sort(nodes, nodes + 1 + n);

int ans = 0, id_min = nodes[0].id;

for(int i = 1; i <= n; i++)

if(ans) printf("%d\n", ans);

else printf("no solution.\n");

}return 0;

}