一
简单的签到题全部输出“NO”即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>P;
const ll maxn = 1e5 + 7;
const ll inf = 1e18 + 7;
const ll mod = 1e9 + 7;
ll t, n, x, k,m,from,to;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
cout << "No\n";
}
return 0;
}
二
签到题,分段函数,分类讨论。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>P;
const ll maxn = 1e5 + 7;
const ll inf = 1e18 + 7;
const ll mod = 1e9 + 7;
ll t, n, x, k,m,from,to;
struct node {
ll l, r;
friend bool operator<(node a, node b) {
if (a.r == b.r)return a.l < b.l;
else return a.r < b.r;
}
};
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
ld ans1 = 0;
ld ans2 = 0;
for (int i = 0; i < n; i++) {
cin >> x;
//一种
if (ans1 + x <= 100)ans1 += x;
else if (ans1 + x > 100 && ans1 + x <= 200) {
if (ans1 < 100)ans1 = 100 + (x - (100 - ans1)) * 0.8;
else ans1 += x * 0.8;
}
else if (ans1 + x > 200) {
if (ans1 < 100) {
ld temp =(x - (100 - ans1));
if (temp <= 125)ans1 = 100 + temp * 0.8;
else ans1 = 200 + (temp - 125) * 0.5;
}
else if (ans1 >= 100 && ans1 < 200) {
if (ans1 + x * 0.8 <= 200)ans1 = ans1 + x * 0.8;
else {
ans1 = 200 + (x - (200-ans1)*1.25) * 0.5;
}
}
else ans1 += x * 0.5;
}
//二种
if (ans2 < 100)ans2 += x;
else if (ans2 >= 100 && ans2 < 200)ans2 += x * 0.8;
else ans2 += x * 0.5;
}
cout << fixed << setprecision(3) << ans1 << " " << ans2 << "\n";
}
return 0;
}
三
线性基模板题,稍微变化下。
#include <iostream>
#include <cstring>
#define ll long long
using namespace std;
struct Linebasis{
ll p[65], b[65];
int cnt;
bool flag;
void init(){
memset(p, 0, sizeof p);
memset(b, 0, sizeof b);
cnt = 0;
flag = false;
}
bool insert(ll x){
for (int i = 62; i >= 0; i--){
if((x >> i) & 1){
if(!p[i]){
p[i] = x;
break;
}
x ^= p[i];
}
}
if(x)
cnt++;
else
flag = true;
return x > 0;
}
ll querymax(ll x = 0){
ll res = x;
for (int i = 62; i >= 0; i--){
if((res^p[i])>res)
res ^= p[i];
}
return res;
}
} base;
int t, n;
ll tmp;
int main(){
cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while(t--){
base.init();
cin >> n;
for (int i = 0; i<n; i++){
cin >> tmp;
base.insert(tmp);
}
cout << base.querymax() << endl;
}
return 0;
}
四
区间dp。
//g[i][j]代表[i,j]区间合法的括号序列方案数(最终答案)
//f[i][j]代表(i,j)区间合法,i,j点上括号匹配的方案数
//g[i][j]+=g[i][k]+f[k+1][r];
//f[i][j]=g[i+1][j-1]*e%mod;
//e代表i,j两个位置能够配对的方案数。
//i=j=0时e=m,具有全部括号种类的配对方案数
//i=0||j=0||i+j=0时,只有一种配对方案
//其他情况不能组成配对
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>P;
const ll maxn = 1e5 + 7;
const ll inf = 1e18 + 7;
const ll mod = 1e9 + 7;
ll t, n, x, k,m,from,to;
struct node {
ll l, r;
friend bool operator<(node a, node b) {
if (a.r == b.r)return a.l < b.l;
else return a.r < b.r;
}
};
ll arr[510];
ll g[510][510], f[510][510];
void init() {
for (int i = 0; i < 510; i++) {
for (int j = 0; j < 510; j++) {
g[i][j] = 0;
f[i][j] = 0;
}
arr[i] = 0;
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
init();
cin >> n >> m;
for (ll i = 1; i <= n; i++)cin >> arr[i];
if (n & 1) {
cout << 0 << "\n"; continue;
}
for (ll i = 0; i <= n; i++)g[i + 1][i] = 1;
for (ll len = 2; len <= n; len += 2) {
for (ll l = 1; l + len - 1 <= n; l++) {
ll r = l + len - 1;
ll e = 0;
if (arr[l] >= 0 && arr[r] <= 0) {
if (arr[l] == 0 && arr[r] == 0)e = m;
else if (arr[l] == 0 || arr[r] == 0 || (arr[l] + arr[r] == 0))e = 1;
else e = 0;
f[l][r] = g[l + 1][r - 1] * e % mod;
}
for (ll k = l; k <= r; k+=2) {
g[l][r] =(g[l][r]+g[l][k-1]*f[k][r]) % mod;
}
}
}
cout << g[1][n] % mod << "\n";
}
return 0;
}
五
贪心,当时没想出来,下附jiangly大佬的代码OTZ(题解Ologn,大佬On线性!)