cf每日刷题c++
目录
Simple Repetition(1000)
Fashionable Array(800)
Kevin and Arithmetic(800)
Permutation Warm-Up(800)
Game of Mathletes(900)
LRC and VIP(800)
Simple Repetition(1000)
https://codeforces.com/problemset/problem/2093/C
#include
using namespace std;
void solve()
{
int n, k;
cin >> n >> k;
if (n == 1)
{
if (k == 2)
{
cout << "YES
";
return;
}
cout << "NO
";
return;
}
if (k > 1)
{
cout << "NO
";
return;
}
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
{
cout << "NO
";
return;
}
}
cout << "YES
";
return;
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Fashionable Array(800)
https://codeforces.com/problemset/problem/2110/A
#include
#include
#include
using namespace std;
void solve()
{
int n;
cin >> n;
vector a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a.begin(), a.end());
int l = 0;
int r = a.size() - 1;
int res = 0;
while (l <= r)
{
if ((a[r] - a[l]) % 2 != 0)
{
l++;
res++;
}
else
{
break;
}
}
int L = 0;
int R = a.size() - 1;
int RES = 0;
while (L <= R)
{
if ((a[R] - a[L]) % 2 != 0)
{
R--;
RES++;
}
else
{
break;
}
}
cout << min(res, RES) << endl;
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Kevin and Arithmetic(800)
https://codeforces.com/problemset/problem/2061/A
#include
using namespace std;
#include
#define int long long
void solve()
{
int res = 0;
int n;
cin >> n;
vector a(n);
int flag = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (a[i] % 2 == 0)
{
flag = 1;
}
}
if (flag)
{
res++;
for (int i = 0; i < n; i++)
{
if (a[i] % 2 == 1)
{
res++;
}
}
}
else
{
res = a.size() - 1;
}
cout << res << endl;
}
signed main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Permutation Warm-Up(800)
https://codeforces.com/problemset/problem/2108/A
#include
using namespace std;
void solve()
{
int n;
cin >> n;
cout << n * n / 4 + 1 << "
";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Game of Mathletes(900)
https://codeforces.com/problemset/problem/2060/C
#include
#include
#include
using namespace std;
void solve()
{
int n, k;
cin >> n >> k;
vector a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a.begin(), a.end());
int res = 0;
int l = 0;
int r = a.size() - 1;
while (l < r)
{
if (a[l] + a[r] == k)
{
res++;
r--;
l++;
}
if (a[l] + a[r] < k)
{
l++;
}
if (a[l] + a[r] > k)
{
r--;
}
}
cout << res << "
";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
LRC and VIP(800)
https://codeforces.com/problemset/problem/2107/A
#include
#include
#include
using namespace std;
void solve()
{
int n;
cin >> n;
vector a(n);
int p = 0;
bool flag = false;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (a[i] > a[p])
{
p = i;
}
if (i >= 1)
{
if (a[i] != a[i - 1])
{
flag = true;
}
}
}
if (!flag)
{
cout << "NO
";
return;
}
cout << "YES
";
for (int i = 0; i < n; i++)
{
if (i == p)
{
cout << 1 << " ";
}
else
{
cout << 2 << " ";
}
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}