Meow~
在 IOICamp2017 解過的題目
自己去 IOICamp 的 Judge 上去看看吧
第一行一個正整數 ,代表測資筆數。每筆測資兩行, 第一行兩個整數 ,第二行 個正整數 。
若所有 跟相距 內位置的數字均不重複 ([i-k,i+k]
) ,就輸出 Yes
,否則輸出 No
。
開 set 亂玩一通
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
set<int> S;
vector<int> V;
int main(void) {
int T, N, k;
ios::sync_with_stdio(false);cin.tie(0);
cin>>T;
while(T--) {
cin >> N >> k;
for(int i=0; i<N; ++i) {
int temp;
cin>>temp;
V.push_back(temp);
}
bool fail=false;
for(int i=0; i<k && i<N; ++i) {
if(S.count(V[i])) { // Fails at the beginning.
fail=true; break;
}
S.insert(V[i]);
}
int i;
if(!fail) {
for(i=k; i<N; ++i) {
if(S.count(V[i])) break;
//else
S.erase(V[i-k]);
S.insert(V[i]);
}
fail = (i!=N);
}
cout << (!fail?"Yes\n":"No\n");
V.clear(); S.clear();
}
return 0;
}
Written on February 12th, 2017 by Kuang-Yu Jeng之前竟然寫了假解 OuO