第一题
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main()
{
int N;
cin >> N;
vector<pii> v(N);
for (int i = 0; i < N; ++i)
{
cin >> v[i].first >> v[i].second;
}
sort(v.begin(), v.end());
int pre = -1;
for (auto &p : v)
{
if (p.second <= pre)
{
cout << "true\n";
return 0;
}
pre = max(pre, p.second);
}
cout << "false\n";
}
第二题
#include <bits/stdc++.h>
using namespace std;
int f(int p, vector<int> &cards)
{
int i = 0, ret = 0;
while (i != cards.size() && cards[i] != p)
++i;
if (i != cards.size())
{
ret = cards.size() - i + 1;
cards.resize(i);
}
else
cards.push_back(p);
return ret;
}
int main()
{
int N, A = 0, B = 0, i = 0, j = 0;
cin >> N;
vector<int> a(N), b(N), cards;
for (int i = 0; i < N; ++i)
cin >> a[i];
for (int i = 0; i < N; ++i)
cin >> b[i];
while (i < N || j < N)
{
while (i < N)
{
int t = f(a[i++], cards);
A += t;
if (t == 0)
break;
}
while (j < N)
{
int t = f(b[j++], cards);
B += t;
if (t == 0)
break;
}
}
for (auto i : cards)
i % 2 ? A++ : B++;
cout << A << " " << B << "\n";
}
第三题
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ll T, A, B, C, Q;
cin >> T;
while (T--)
{
cin >> A >> B >> C >> Q;
if (C == 1)
{
if ((Q - A) % B == 0)
cout << "1\n";
else
cout << "0\n";
}
else
{
ll flag = 0, t = A;
while (t <= Q)
{
if (t % B == Q % B)
{
flag = 1;
break;
}
t *= C;
}
if (flag)
cout << "1\n";
else
cout << "0\n";
}
}
}
第四题
#include <bits/stdc++.h>
using namespace std;
string mul(string &a, string &b)
{
int n = a.size(), m = b.size(), c = 0;
vector<int> v(n + m, 0);
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
v[i + j] += (a[i] - '0') * (b[j] - '0');
}
}
string res;
for (int i = 0; i < n + m; ++i)
{
c += v[i];
res += char(c % 10 + '0');
c /= 10;
}
reverse(res.begin(), res.end());
while (res.size() > 1 && res[0] == '0')
res.erase(res.begin());
return res;
}
int main()
{
string s;
for (int i = 0, t; i < 10; ++i)
{
cin >> t;
if (t != 0)
s += string(t, char(i + '0'));
}
sort(s.rbegin(), s.rend());
string a, b;
bool flag = true;
for (int i = 0, j = 1; i < s.size(); i += 2, j += 2)
{
if (j == s.size())
{
if (flag)
a += s[i];
else
b += s[i];
break;
}
if (flag && s[i] == s[j])
{
a += s[i];
b += s[j];
}
else if (flag)
{
a += s[i];
b += s[j];
flag = false;
}
else
{
a += s[j];
b += s[i];
}
}
cout << mul(a, b) << "\n";
}
#拼多多笔试##学习路径#