题目链接:https://codeforces.com/contest/1248
水题
#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
typedef long long ll;
int a[mx],b[mx];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d",&n);
ll c[2] = {0,0};
ll d[2] = {0,0};
for (int i=1;i<=n;i++) {
scanf("%d",a+i);
c[a[i]%2]++;
}
scanf("%d",&m);
for (int i=1;i<=m;i++) {
scanf("%d",b+i);
d[b[i]%2]++;
}
printf("%lld\n",c[0]*d[0]+c[1]*d[1]);
}
return 0;
}
意思就是一半的和做一边,另一半的和做另一边,平方的话让一边越大越好就行了
#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
typedef long long ll;
int a[mx],b[mx];
int main(){
int n;
scanf("%d",&n);
int sum = 0;
for(int i=1;i<=n;i++){
scanf("%d",a+i);
sum += a[i];
}
sort(a+1,a+1+n);
int beg = n / 2,ret = 0;
for (int i=1;i<=beg;i++)
ret += a[i];
printf("%lld\n",1ll*ret*ret+1ll*(sum-ret)*(sum-ret));
return 0;
}
C - Ivan the Fool and the Probability Theory
不难证明除了黑白交替的方块意外,其他的方块数都是取决于第一行的摆放方案,后面跟随第一行都摆放都是固定的。然后一行的dp方案只要记最后是连续两个一样的还是不一样的方案数就可以,另外行数对黑白交替的方案数的影响其实是一样的。
#include<bits/stdc++.h>