T1 xiaoxin juju needs help

计算组合数然后多重集排列乱搞,注意判无解情况(TM我就判错然后FST了)。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
const int maxn=1010;
const int mod=1000000007;
int n,c[26];
char s[maxn];
ll C[maxn][maxn];
void solve() {
memset(c,0,sizeof(c));
scanf("%s",s+1);n=strlen(s+1);
rep(i,1,n) c[s[i]-'a']++;
int sum=0;
rep(i,0,25) {
if(c[i]&1) sum++,c[i]--;
c[i]>>=1;
}
if(sum>1) {puts("0");return;}
ll ans=1;int cur=0;
rep(i,0,25) {
cur+=c[i];
(ans*=C[cur][c[i]])%=mod;
}
printf("%I64d\n",ans);
}
int main() {
C[0][0]=1;
rep(i,1,1000) {
C[i][0]=C[i][i]=1;
rep(j,1,i-1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
dwn(T,read(),1) solve();
return 0;
}

T2 India and China Origins

转化成对偶图然后统计八连块联通性。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
const int mx[]={0,0,1,-1,1,-1,1,-1};
const int my[]={1,-1,0,0,1,1,-1,-1};
const int maxn=510;
int pa[maxn*maxn],n,m;
int id(int i,int j) {return (i-1)*m+j;}
char s[maxn];
int findset(int x) {return pa[x]==x?x:pa[x]=findset(pa[x]);}
void Add(int x,int y) {
pa[id(x,y)]=id(x,y);
rep(dir,0,7) {
int nx=x+mx[dir],ny=y+my[dir];
if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&pa[id(nx,ny)]) pa[findset(id(nx,ny))]=findset(id(x,y));
}
}
void solve() {
n=read();m=read();int S=n*m+1,T=n*m+2;
memset(pa,0,sizeof(pa));pa[S]=S;pa[T]=T;
rep(i,1,n) {
scanf("%s",s+1);
rep(j,1,m) {
if(s[j]=='1') Add(i,j);
if(j==1&&s[j]=='1') pa[findset(S)]=findset(id(i,j));
if(j==m&&s[j]=='1') pa[findset(T)]=findset(id(i,j));
}
}
int k=read(),ok=0;
if(findset(S)==findset(T)) {puts("0");ok=1;}
rep(i,1,k) {
int x=read()+1,y=read()+1;
Add(x,y);
if(y==1) pa[findset(S)]=findset(id(x,y));
if(y==m) pa[findset(T)]=findset(id(x,y));
if(!ok&&findset(S)==findset(T)) {printf("%d\n",i);ok=1;}
}
if(!ok) printf("-1\n");
}
int main() {
dwn(T,read(),1) solve();
return 0;
}

T3 Bomber Man wants to bomb an Array.

直接DP,发现一个转移是否合法只取决于区间内是否恰好有一个点。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
const int maxn=2010;
double score(int len) {return log2(len);}
int n,m,S[maxn];
double f[maxn];
void solve() {
n=read();m=read();
memset(S,0,sizeof(S));
rep(i,1,m) S[read()+1]++;
rep(i,1,n) S[i]+=S[i-1];
f[0]=0.0;
rep(i,1,n) {
f[i]=0.0;
rep(j,0,i-1) if(S[i]-S[j]==1) f[i]=max(f[i],f[j]+score(i-j));
}
printf("%.0lf\n",floor(1000000*f[n]));
}
int main() {
dwn(T,read(),1) solve();
return 0;
}

T4 xiaoxin and his watermelon candy

先暴力哈希,然后转化成区间不同数的个数查询,离线树状数组随便做做。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<ctime>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
typedef unsigned long long ull;
const int maxn=200010;
ull X,val[maxn],tmp[maxn];
int n,m,A[maxn];
struct Query {
int l,r,id;
bool operator < (const Query& ths) const {
return l<ths.l;
}
}Q[maxn];
int last[maxn],f[maxn];
int sumv[maxn],ans[maxn];
int sum(int x) {int res=0;for(;x;x-=x&-x) res+=sumv[x];return res;}
void add(int x,int v) {for(;x<=n;x+=x&-x) sumv[x]+=v;}
void solve() {
n=read();
rep(i,1,n) A[i]=read()+1,sumv[i]=0;
if(n>=3) {
rep(i,1,n-2) {
if(A[i]<=A[i+1]&&A[i+1]<=A[i+2]) val[i]=X*X*A[i]+X*A[i+1]+(ull)A[i+2];
else val[i]=0;
tmp[i]=val[i];
}
sort(tmp+1,tmp+n-1);
rep(i,1,n-2) {
if(!val[i]) A[i]=0;
else A[i]=lower_bound(tmp+1,tmp+n-1,val[i])-tmp;
}
rep(i,0,n) last[i]=n+1;
dwn(i,n-2,1) f[i]=last[A[i]],last[A[i]]=i;
rep(i,1,n) if(last[i]<n) add(last[i],1);
m=read();
rep(i,1,m) Q[Q[i].id=i].l=read(),Q[i].r=read()-2;
sort(Q+1,Q+m+1);int cur=1;
rep(i,1,m) {
while(cur<Q[i].l&&cur<=n-2) {
if(A[cur]) add(cur,-1),add(f[cur],1);
cur++;
}
if(Q[i].l<=Q[i].r) ans[Q[i].id]=sum(Q[i].r)-sum(Q[i].l-1);
else ans[Q[i].id]=0;
}
rep(i,1,m) printf("%d\n",ans[i]);
}
else {
m=read();
rep(i,1,m) read(),read(),printf("%d\n",0);
}
}
int main() {
X=52501;srand(time(0));
dwn(i,rand()%10+5,1) X=X*233333;
dwn(T,read(),1) solve();
return 0;
}

  

BestCoder Round #77的更多相关文章

  1. hdu 5652 India and China Origins(二分+bfs || 并查集)BestCoder Round #77 (div.2)

    题意: 给一个n*m的矩阵作为地图,0为通路,1为阻碍.只能向上下左右四个方向走.每一年会在一个通路上长出一个阻碍,求第几年最上面一行与最下面一行会被隔开. 输入: 首行一个整数t,表示共有t组数据. ...

  2. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

  3. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  4. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  5. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  6. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  7. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  8. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  9. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

随机推荐

  1. uploadify文件批量上传

    uploadify能够时间文件的批量上传,JS文件包下载地址,使用说明可以参考官网文档(http://www.uploadify.com/documentation/) 使用方法如下代码: $(&qu ...

  2. Web框架本质

    Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. #!/usr/bin/env python #coding:utf- ...

  3. 【PHP&&FileIO】

    在程序员的眼中,文件不应当仅仅是一部电影.一首歌曲.一个pdf文件,它应该被视为一个文件夹,而我们所熟知的文件,应当是它的特例. 在web开发中,文件的上传和下载是文件变成的一个实际应用. 延续cru ...

  4. 快速熟悉python 下使用mysql(MySQLdb)

    首先你需要安装上mysql和MySQLdb模块(当然还有其他模块可以用),这里我就略过了,如果遇到问题自行百度(或者评论在下面我可以帮忙看看) 这里简单记录一下自己使用的学习过程: 一.连接数据库 M ...

  5. long和int的区别

    转自:http://blog.sina.com.cn/s/blog_6f62c9510101svjz.html 突然间就想到了long和int到底什么区别(发现有很多问题都是突然间想到的),然后百度. ...

  6. zzy:java采用的是16位的Unicode字符集作为编码方式------理解

    java语言使用16位的Unicode字符集作为编码方式,是疯狂Java中的原话. 1,编码方式只是针对字符类型的(不包括字符串类,数值类型int等,这些只是在解释[执行]的时候放到Jvm的不同内存块 ...

  7. APP设计师拿到APP产品原型开始,七步搞定APP设计(转)

    任何一款成功的APP都需要以坚实的产品概念作为基础,因为概念决定了产品最终完成的潜力. 一般情况下,交到app设计师手里的都是移动app产品原型图.当然这个是在移动产品经理反复斟酌,并且与大家开会讨论 ...

  8. Codeforces Round #212 (Div. 2) D. Fools and Foolproof Roads 并查集+优先队列

    D. Fools and Foolproof Roads   You must have heard all about the Foolland on your Geography lessons. ...

  9. HDU 3586 Information Disturbing 树形DP+二分

    Information Disturbing Problem Description   In the battlefield , an effective way to defeat enemies ...

  10. pythonchallenge之C++学习篇-02

    第二关任然是一个字符处理的关卡 查看网页源码发现有一大串字符需要处理,这么多的字符如果放在源代码里就很不好了 所以要用到C++对文件的操作,用到的头文件是fstream 这里参照了这个博文 对文件处理 ...