涉及知识点:
- 思维
solution
- 题意大概就是使用不超过 n*(n - 1) / 2 - 1次操纵使其完全递增
- 其实其只要不是完全递减的序列就好了
std:
#include <iostream>
using namespace std;
int main()
{
int t;
int n;
cin >> t;
while(t --)
{
cin >> n;
bool tf = false;
int a,b;
b = 1e9 + 10;
for(int i = 0;i < n;i ++)
{
cin >> a;
if(b > a){
b = a;
}
else{
tf = true;
}
}
if(tf){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
return 0;
}
涉及知识点:
- 思维
solution
- 题意大概就是 The task is to calculate the number of such pairs (i,j) that i<j and ai & aj≥ai⊕aj, where & denotes the bitwise AND operation, and ⊕ denotes the bitwise XOR operation.
- 其实就是二进制的拓展,稍微懂一点二进制就能完全做出这个题
#include <iostream>
#include <cstring>
using namespace std;
const int N = 60;
long long a[N];
int main()
{
int t;
int n;
cin >> t;
while(t --)
{
cin >> n;
int x;
long long res = 0;
memset(a,0,sizeof a);
for(int i = 0;i < n;i ++)
{
cin >> x;
for(int i = 31;i >= 0;i --)
{
if(x >> i & 1){
a[i]++;
break;
}
}
}
for(int i = 0;i <= 31;i ++)
{
// cout << a[i] << ' ';
res += (0 + a[i] - 1) * a[i] / 2;
}
// cout << endl;
cout << res << endl;
}
return 0;
}
涉及知识点:
- dp
solution
- 题意大概就是找出最大值,a1-a2+a3-a4····这个序列的最大值
- 我认为是对背包的一点拓展
- 对于当前这个物品有选和不选两种选择,还有如果选了当前这个数变为总数为偶数还是奇数
- 不选或者选完为偶数
- dp[i][0] = max(dp[i - 1][0],dp[i - 1][1] - x);
- 不选或者是选完为奇数
- dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] + x);
#include <iostream>
#include <cstring>
using namespace std;
const int N = 3e5 + 10;
long long dp[N][2];
int main()
{
int t, n,p;
cin >> t;
while(t --)
{
dp[0][0] = dp[0][1] = 0;
cin >> n >> p;
long long x;
long long a = 0,b = 0;
for(int i = 1;i <= n;i ++)
{
cin >> x;
dp[i][0] = max(dp[i - 1][0],dp[i - 1][1] - x);
dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] + x);
}
cout << max(dp[n][0],dp[n][1]) << endl;
}
return 0;
}
涉及知识点:
- 优先队列