3.数学奇才
可以进行n次变相反数的操作,那就全变正数就好了。
#include <cmath>
#include <iostream>
using namespace std;
typedef long long LL;
int n;
int main()
{
// 请在此输入您的代码
cin >> n;
LL res = 0;
for(int i = 0; i < n; i ++ )
{
LL x; cin >> x;
res += abs(x);
}
cout << res;
return 0;
}
4.你不干?有的是帕鲁干
分类讨论,平方差 = (x - y) * (x + y) 然后又要是连续的正奇数,肯定就是(x + 2 - x) * (x + 2 + x),所以化简就可以得第一个奇数为x = (y - 4) / 4,显然,y一定要大于8才可以。
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
// 请在此输入您的代码
int T;
cin >> T;
while(T -- )
{
LL x; cin >> x;
if(x < 8) puts("No");
else
{
LL t = x - 4;
if(t % 4 || t / 4 % 2) puts("No");
else
{
t /= 4;
puts("Yes");
cout << t << ' ' << t + 2 << endl;
}
}
}
return 0;
}
5.等腰三角形
模拟,贪心
设第三边为x, 另外两边为b, 0 < x < 2 * b,所以这个第三边满足条件的,从小到大枚举找答案就完事了。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n;
int a[N], b[N];
vector<int> c;
set<int> ss;
map<int, int> cnt_a;
map<int, int> cnt_b;
int main()
{
// 请在此输入您的代码
cin >> n;
for(int i = 0; i < n; i ++ )
{
cin >> a[i];
cnt_a[a[i]] ++;
}
for(int i = 0; i < n; i ++ )
{
cin >> b[i];
cnt_b[b[i]] ++;
ss.insert(b[i]);
}
for(auto x : ss)
c.push_back(x);
LL res = 0;
int j = 0;
for(auto [x, y] : cnt_a)
{
int t = y;
while(j < c.size())
{
if(c[j] >= 2 * x) break;
int d = min(t, cnt_b[c[j]]);
res += d;
t -= d;
cnt_b[c[j]] -= d;
if(!cnt_b[c[j]]) j ++;
if(!t) break;
}
}
cout << res;
return 0;
}
6.计算方程
二分找答案,因为有个根号在,所以在用实数比较时, 要开一个边界值为eps,其它就是带公式了。
#include <cmath>
#include <iostream>
using namespace std;
typedef long long LL;
const double eps = 1e-8;
bool check(LL x, int k, int m)
{
double a = sqrt(x);
LL b = log(x) / log(k);
return a + b - m >= eps;
}
int main()
{
// 请在此输入您的代码
int T;
cin >> T;
while(T -- )
{
int k, m;
cin >> k >> m;
LL l = 1, r = 1e18;
while(l < r)
{
LL mid = l + r >> 1;
if(check(mid, k, m)) r = mid;
else l = mid + 1;
}
cout << r << endl;
}
return 0;
}