放假了心血来潮,水几个题
parent
bfc26a4531
commit
20653e35d8
@ -0,0 +1,4 @@
|
||||
add_executable(a a.cpp)
|
||||
add_executable(b b.cpp)
|
||||
add_executable(c c.cpp)
|
||||
add_executable(d d.cpp)
|
||||
@ -0,0 +1,15 @@
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
int n, arr[100];
|
||||
int main()
|
||||
{
|
||||
scanf("%d", &n);
|
||||
for (int i = n; i--;)
|
||||
scanf("%d", arr + i);
|
||||
std::sort(arr, arr + n);
|
||||
if (arr[0] == arr[(n >> 1) - 1] && arr[n >> 1] == arr[n - 1] && arr[0] != arr[n - 1])
|
||||
printf("YES\n%d %d", arr[0], arr[n - 1]);
|
||||
else
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <set>
|
||||
int n;
|
||||
char str[201];
|
||||
int main()
|
||||
{
|
||||
scanf("%d%s", &n, str);
|
||||
std::set<char> S;
|
||||
int ans = 0;
|
||||
for (int pos = 0; pos <= n; pos++)
|
||||
if (islower(str[pos]))
|
||||
S.insert(str[pos]);
|
||||
else
|
||||
ans = std::max(ans, static_cast<int>(S.size())), S.clear();
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
#include <cstdio>
|
||||
int main()
|
||||
{
|
||||
int a, b, f, k, r, ans = 0;
|
||||
for (scanf("%d%d%d%d", &a, &b, &f, &k), r = b; k--; f = a - f)
|
||||
if (r < f || b < a - f)
|
||||
return puts("-1"), 0;
|
||||
else if (r >= a + (k ? a - f : 0))
|
||||
r -= a;
|
||||
else
|
||||
ans++, r = b - a + f;
|
||||
return printf("%d", ans), 0;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
inline void readint(int &x)
|
||||
{
|
||||
int ch = x = 0;
|
||||
while (!isdigit(ch = getchar())) 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
}
|
||||
const int N = 200020;
|
||||
int arr[N], cnt[N], n, ans;
|
||||
bool used[N];
|
||||
int main()
|
||||
{
|
||||
readint(n);
|
||||
for (int i = 0; i < n; i++) readint(arr[i]), ans += cnt[arr[i]]++ > 0;
|
||||
printf("%d\n", ans);
|
||||
for (int i = 0, x = 1; i < n; i++)
|
||||
if (cnt[arr[i]] > 1)
|
||||
{
|
||||
while (cnt[x]) x++;
|
||||
if (arr[i] > x || used[arr[i]])
|
||||
cnt[arr[i]]--, cnt[arr[i] = x]++;
|
||||
else
|
||||
used[arr[i]] = true;
|
||||
}
|
||||
for (int i = 0; i < n; i++) printf("%d ", arr[i]);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue