这次的题目挺简单的awa
A
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b; cin>>a>>b;
cout<<a*(a-1)/2+b*(b-1)/2;
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
bool ok(string s){
string t=s;
reverse(s.begin(), s.end());
return t==s;
}
int main(){
string s; cin>>s;
if(!ok(s)){
puts("No");
return 0;
}
int n=s.size();
s=' '+s;
if(ok(s.substr(1, (n-1)/2)) && ok(s.substr((n+3)/2))) puts("Yes");
else puts("No");
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
int main(){
double x; cin>>x; x/=3;
printf("%.10lf", x*x*x);
return 0;
}
D
维护一个桶和相关信息即可。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=2e5+5;
int n;
int w[N];
int buc[N];
ll cal(int x){
return 1LL*x*(x-1)/2;
}
int main(){
read(n);
rep(i,1,n) read(w[i]), buc[w[i]]++;
ll cur=0;
rep(i,1,n) cur+=cal(buc[i]);
int pre=0;
rep(i,1,n){
int v=w[i];
cur-=buc[w[i]]-1;
buc[w[i]]--;
cur+=buc[pre];
buc[pre]++;
pre=w[i];
cout<<cur<<endl;
}
return 0;
}
E
注意到行数很小,所以可以直接枚举,然后大力贪心即可。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=1005;
int n, m, k;
int w[15][N], s[15][N];
int cal(int a, int b, int c, int d){
if(!a && !b) return s[c][d];
if(!a) return s[c][d]-s[c][b-1];
if(!b) return s[c][d]-s[a-1][d];
return s[c][d]-s[a-1][d]-s[c][b-1]+s[a-1][b-1];
}
int p[15], tot;
int main(){
read(n), read(m), read(k);
rep(i,0,n-1) rep(j,0,m-1){
char t; cin>>t;
s[i][j]=w[i][j]=t=='1';
if(i) s[i][j]+=s[i-1][j];
if(j) s[i][j]+=s[i][j-1];
if(i && j) s[i][j]-=s[i-1][j-1];
}
int res=INF;
rep(i,0,(1<<n-1)-1){
int tmp=0;
tot=0;
p[0]=-1;
rep(j,0,n-1) if(i>>j&1) p[++tot]=j;
p[++tot]=n-1;
tmp=tot-1;
// debug(i);
// rep(i,1,tot) debug(p[i]);
int last=0; // last column
bool ok=true;
rep(c,0,m-1){
int cur=0;
rep(x,1,tot) cur=max(cur, cal(p[x-1]+1, last, p[x], c))/*, debug(last)*/;
// debug(cur);
if(cur>k && last==c){
ok=false;
break;
}
if(cur>k){
last=c;
tmp++;
}
}
if(ok) res=min(res, tmp);
}
// rep(i,0,n-1){
// rep(j,0,m-1) cerr<<cal(i, j, i, j)<<' ';
// cerr<<endl;
// }
cout<<res<<endl;
return 0;
}
F
\(f[x]\) 表示和为 \(x\) 左端选择方案个数。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define int long long
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=3030, mod=998244353;
int n, s;
int w[N], f[N];
signed main(){
read(n), read(s);
rep(i,1,n) read(w[i]);
int res=0;
rep(i,1,n){
if(w[i]>s) continue;
else{
dwn(j,s,w[i]+1) f[j]=(f[j-w[i]]+f[j])%mod;
f[w[i]]=(f[w[i]]+i)%mod;
res=(res+f[s]*(n-i+1)%mod)%mod;
f[s]=0;
}
}
cout<<res<<endl;
return 0;
}