目前是百度之星的资格赛比赛时间,写对一道题就可以进入后面的比赛了,我们初赛再见咯。明明昨天就上传该文章,可惜图片太多一直列为待审核,现在图片都删了,日后再来详细补充题目吧。
###调查问卷
#include
using namespace std;
#define se second
#define fi first
#define ll long long
const int MAXN = (int)1e3+10;
int n, m, k;
char s[MAXN][11];
int dp[MAXN][11];
int arr[MAXN];
map mp;
signed main() {
int T, kk = 0;
scanf("%d",&T);
while(T--) {
cin >> n >> m >> k;
for(int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int ans = 0;
for(int i = 1; i < 1 << m; i++) {
int zz = 0;
for(int j = 0; j < m; j++) {
if(i & (1 << j)) {
for(int l = 0; l < n; l++) {
dp[l][zz] = s[l][j] - 'A' + 1;
}
zz++;
}
}
memset(arr, 0, sizeof arr);
for(int j = 0; j < n; j++) {
for(int l = 0; l < zz; l++) {
arr[j] <<= 1;
arr[j] |= (dp[j][l] == 1 ? 1 : 0);
}
}
mp.clear();
for(int j = 0; j < n; j++) mp[arr[j]]++;
int tmp = 0;
for(auto it = mp.begin(); it != mp.end(); ++it) {
tmp += (n - it->se) * it->se;
}
if(tmp / 2 >= k) ans++;
}
printf("Case #%d: %d\n", ++kk, ans);
}
return 0;
}
###字串查询
#include
using namespace std;
#define LL long long
#define pb push_back
#define inf 0x3f3f3f3f
char s[100010];
LL f[100010][26];
int main(){
int t,n,q,m,i,j,k,cas=0,l,r;
scanf("%d",&t);
while(t--){
scanf("%d%d%s",&n,&q,s+1);
for(i=1;i<=n;++i){
for(j=0;j<26;++j) f[i][j]=f[i-1][j];
f[i][s[i]-'A']++;
}
printf("Case #%d:\n",++cas);
while(q--){
scanf("%d%d",&l,&r);
LL ans=0;
for(i=0;i<26;++i){
if(f[r][i]-f[l-1][i]){
ans=f[r][i]-f[l-1][i];
break;
}
}
printf("%I64d\n",ans);
}
}
return 0;
}
###序列计数
#include
using namespace std;
#define LL long long
#define pb push_back
#define inf 0x3f3f3f3f
LL mod=1e9+7;
int a[10010],N,M;
LL C[10010],ans[10010],f[2][10010];
inline int lowbit(int x){return x&-x;};
inline void add(int x,LL d){
while(x<=N){
C[x]+=d;
C[x]%=mod;
x+=lowbit(x);
}
}
inline LL sum(int x){
LL r=0;
while(x){
r+=C[x];
r%=mod;
x-=lowbit(x);
}
return r;
}
inline void scan_d(int &ret)
{
char c;
ret = 0;
while ((c = getchar()) < '0' || c > '9');
while (c >= '0' && c <= '9')
{
ret = ret * 10 + (c - '0'), c = getchar();
}
}
int main(){
int t,n,m,i,j,k,cas=0;
char ch;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
N=n;
for(i=1;i<=n;++i) scan_d(a[i])/*scanf("%d",a+i)*/,f[0][i]=1;
ans[1]=n;
int cur=1;
for(int len=2;len<=n;++len){
ans[len]=0;
if(ans[len-1]==0) continue;
for(i=1;i<=n;++i){
LL tmp=sum(a[i]-1);
ans[len]+=tmp;
add(a[i],f[cur^1][i]);
f[cur][i]=tmp;
}
for(i=1;i<=n;++i)C[i]=0;
cur^=1;
}
printf("Case #%d:",++cas);
for(i=1;i<=n;++i) printf(" %I64d",ans[i]%mod);
cout<
###三原色图
#include
using namespace std;
#define LL long long
#define pb push_back
#define inf 0x3f3f3f3f
int f[111];
int getf(int u){return f[u]==u?u:f[u]=getf(f[u]);}
struct Edge{
int u,v,w,col,sel;
bool operator<(const Edge& C)const{
return w>ch;
if(ch=='R') e[i].col=0;
else if(ch=='G') e[i].col=1;
else if(ch=='B') e[i].col=2;
}
sort(e+1,e+1+m);
memset(ans,-1,sizeof(ans));
mst(0);
mst(2);
printf("Case #%d:\n",++cas);
for(i=1;i<=m;++i) printf("%d\n",ans[i]);
}
return 0;
}