题目来源:2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)
A.Cakey McCakeFace
#include <bits/stdc++.h>
#define pb(x) push_back(x)
typedef long long ll;
const int maxn = 2000+7;
using namespace std;
int n,m;
ll a[maxn], b[maxn];
map<ll, ll> Ma, Mb, M;
ll anst,ans;
int main() {scanf("%d%d",&n,&m);for(int i=0;i<n;++i)scanf("%lld",&a[i]),++Ma[a[i]];for(int i=0;i<m;++i)scanf("%lld",&b[i]),++Mb[b[i]];for(auto x1: Ma){for(auto x2: Mb)if(x1.first<=x2.first){M[x2.first-x1.first]+=min(x1.second,x2.second);}}for(auto x: M){if(x.second > anst){anst = x.second;ans = x.first;}}printf("%lld\n",ans);return 0;
}
C.Macarons
状压dp+矩阵快速幂裸题,然而。。。注意到矩阵乘法的复杂度很高,一个多余的mod,就会导致慢2倍以上,会TLE。。。好吧常数优化,太重要了。。。还发现结构体里的数组,开太大,会导致代码,崩的某名奇妙!!
#include <cstdio>
#define rg register
#define pb(x) push_back(x)
typedef long long ll;
inline int readint(){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;
}
inline ll readll(){char c=getchar();ll x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;
}
const ll mod = 1000000000;
int n;
ll m, ans[260][260], ans1[260][260], a[260][260], c[260][260], d[260][260];
inline void dfs(int ss, int s, int x, int t) {if(x>=n){++a[t][ss],a[t][ss]%=mod;return;}if(!(s&(1<<x))){dfs(ss,s|(1<<x),x+1,t);// 1*1dfs(ss,s|(1<<x),x+1,t|(1<<x));// 1*2if(x+1<n&&!(s&(1<<(x+1)))) dfs(ss,s|(1<<x)|(1<<(x+1)),x+2,t);// 2*1}else dfs(ss,s,x+1,t);
}
inline void mul(ll a[][260], ll b[][260], int n){for(rg int i=0;i<n;++i)for(int j=0;j<n;++j)ans[i][j]=0,c[i][j]=a[i][j],d[i][j]=b[i][j];for(rg int i=0;i<n;++i)for(rg int k=0;k<n;++k)if(c[i][k])for(rg int j=0;j<n;++j)if(d[k][j]){ans[i][j] = (ans[i][j] + (c[i][k]*d[k][j]))%mod;//TLE!!!: ans[i][j] = (ans[i][j] + (c[i][k]*d[k][j])%mod)%mod;}for(rg int i=0;i<n;++i)for(rg int j=0;j<n;++j)a[i][j]=ans[i][j];
}
ll L;
int main() {n=readint(),m=readll();L = (1<<n);for(int s=0;s<L;++s){ans1[s][s]=1;dfs(s,s,0,0);}while(m != 0) {if(m&1)mul(ans1,a,L);if(ans1[0][0]==0)break;mul(a,a,L); m>>=1;if(ans1[0][0]==0)break;}printf("%lld\n",ans1[0][0]%mod);return 0;
}
J.Frosting on the Cake
相当于多项式乘法,然而,刚入门fft的我,直接写了fft。。。wa,应该是精度被卡,实际上,可以把三种颜色,直接分开算出来。
K.Blowing Candles
之前一直不会旋转卡壳,原理不难理解,只是计算几何的代码,感觉好难写。等写好了再贴出来吧