A. Cubes Sorting
题意思路:看一下是不是降序即可
代码:
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>
#define LL long long
using namespace std;
#define MAXN 100011
#define inf 100000001
#define sd1(i) scanf("%d", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
int T;
int N;
int a[MAXN];
int main(){
sd1(T);
while(T--){
sd1(N);
int flag = 0;
for(int i =0 ; i < N; i++){
sd1(a[i]);
}
for(int i = 1; i < N; i++){
if(a[i] >= a[i-1]) flag = 1;
}
if(flag == 1) cout << "YES" << endl;
else cout << "NO" << endl;
}
//system("pause");
}
B. Rock and Lever
题意: such pairs (i,j) that i<j and (ai & aj) ≥ (ai⊕aj)
思路 :对于位运算不是很了解 刚开始进行遍历 超时 查阅资料后才发现
C1. Pokémon Army (easy version)
题意: 找一个子串,使a1-a2+a3-a4…最大
思路: dp,用两个数组记录一下,一个记录下一个加的,另一个记录下一个减的
转移方程:dp[i][0] = max(dp[i-1][0], dp[i-1][1] - a[i]); dp[i][1] = max(dp[i-1][1], dp[i-1][0] + a[i]);
注意 : 1,卡LL 2,memset不知为何超时
代码:
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>
#define LL long long
using namespace std;
#define MAXN 300011
#define sd1(i) scanf("%d", &i)
#define sl1(i) scanf("%lld", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
LL T, N;
LL a[MAXN];
LL dp[MAXN][2];
LL n, q;
int main(){
sd1(T);
while(T--){
sl2(n, q);
LL sum = 0;
for(int i = 1; i <= n; i++){
sl1(a[i]);
}
for(int i =0; i<= n; i++){
for(int j = 0; j < 2; j++){
dp[i][j] = 0;
}
}
for(int i = 1; i <= n; i++){
dp[i][0] = max(dp[i-1][0], dp[i-1][1] - a[i]);
dp[i][1] = max(dp[i-1][1], dp[i-1][0] + a[i]);
//cout << dp[i][0] << ' ' << dp[i][1] << endl;
}
sum = max(dp[n][0], dp[n][1]);
printf("%lld\n", sum);
}
//system("pause");
return 0;
}