abc 321 B
// 没有考虑到当此时成绩已经足够时直接输出 0 的情况
#include <iostream>
using namespace std;
int n, m;
int minn, maxn, res;
int main()
{
minn = 101, maxn = -1;
cin >> n >> m;
for (int i = 0; i < n - 1; i ++)
{
int a;
cin >> a;
res += a;
minn = min(a, minn);
maxn = max(a, maxn);
}
if (res - maxn >= m)
{
cout << 0 << endl;
return 0;
}
int k = m - res + minn + maxn;
if (k < maxn && k > minn) cout << k << endl;
else if (k == minn) cout << 0 << endl;
else if (k == maxn) cout << maxn << endl;
else cout << -1 << endl;
return 0;
}
输入一个数,输出A,A^A 等于此数,若无,输出-1
// 快速幂,需要防溢出,对于ULL 来说,界限是2e64,大概为 16 * 10 ^ 18
// 由于B的范围是 1e18,可以算出大概的放溢出范围
#include <iostream>
using namespace std;
typedef unsigned long long ULL;
const ULL inf = 2E18;
ULL b;
ULL qmi(ULL a, ULL b)
{
ULL res = 1;
for (; b; b /= 2, a *= a, a = min(a, inf))
{
if (b % 2) res *= a;
}
return res;
}
int main()
{
cin >> b;
for (ULL i = 1; qmi(i, i) <= b; i ++)
{
if (qmi(i, i) == b)
{
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
abc 325 B
UTC 协调世界时(世界标准时间) 对于 0 和 23 来说,只隔了 1 小时
abc 324 B
要记得看数据范围啊