https://ac.nowcoder.com/acm/contest/372#question
A.救救猫咪
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int N; struct Node {
int x;
int y;
int cnt;
}node[maxn]; int main() {
scanf("%d", &N);
for(int i = ; i < N; i ++)
scanf("%d%d", &node[i].x, &node[i].y); for(int i = ; i < N; i ++) {
for(int j = ; j < N; j ++) {
if(node[j].x > node[i].x && node[j].y > node[i].y)
node[i].cnt ++;
}
} for(int i = ; i < N; i ++)
printf("%d\n", node[i].cnt);
return ;
}
B.救救兔子
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int N, M;
int num[maxn]; int main() {
scanf("%d", &N);
for(int i = ; i < N; i ++)
scanf("%d", &num[i]); sort(num, num + N);
scanf("%d", &M);
while(M --) {
int x;
scanf("%d", &x);
int l = , r = N - , mid;
while(l <= r) {
mid = (l + r) / ;
if(x > num[mid]) l = mid + ;
else if(x == num[mid]) break;
else r = mid - ;
}
if(num[mid] == x)
printf("%d\n", num[mid]);
else if(num[mid] > x) {
if(mid == ) printf("%d\n", num[mid]);
else if((num[mid] - x) >= (x - num[mid - ]))
printf("%d\n", num[mid - ]);
else printf("%d\n", num[mid]);
}
else {
if(mid == N - )
printf("%d\n", num[mid]);
else if((num[mid + ] - x) >= (x - num[mid]))
printf("%d\n", num[mid]);
else printf("%d\n", num[mid + ]);
} }
return ;
}
C.救救企鹅
#include <bits/stdc++.h>
using namespace std; string s, a, b; int main() {
cin >> s >> a >> b;
int sign;
sign = s.find(a, );
while(sign != string::npos) {
s.replace(sign, a.size(), b);
sign = s.find(a, sign + );
}
cout << s;
return ;
}
D.数糖纸
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e6 + ;
int N;
int num[maxn];
map<int, int> mp; int main() {
scanf("%d", &N);
for(int i = ; i < N; i ++)
scanf("%d", &num[i]); set<int> s;
int L = , R = , ans = ;
while(R < N) {
while(R < N && !s.count(num[R])) {
s.insert(num[R]);
//mp[num[R]] ++;
R ++;
}
ans = max(ans, R - L);
s.erase(num[L]);
//mp[num[L]] = 0;
L ++;
}
printf("%d\n", ans);
return ;
}
D 题用 map 会超时