Atcoder&CodeForces杂题11.6

Preface

NOIP前突然不知道做什么,感觉思维有点僵化,就在vjudge上随便组了6道ABC D+CF Div2 C/D做,发现比赛质量还不错,知识点涉及广,难度有梯度,码量稍小,思维较多. 同时发现vjudge的比赛功能很不错

A. ABC112-D-Partition

int n,m;
int main(){
for(ri i=m/n;i>=1;i--){
if(m%i==0){printf("%d\n",i);break;}
}
return 0;
}


B. ABC110-D-Factorization

int n,m;
int c[maxn],tot=0;
ll fac[maxn],inv_fac[maxn];
ll C(int n,int m){
return fac[m]*inv_fac[n]%P*inv_fac[m-n]%P;
}
ll ksm(ll a){
ll ans=1;
ll c=P-2;
while(c){
if(c&1)ans=ans*a%P;
a=a*a%P;
c=c>>1;
}
return ans%P;
}
int main(){
int x,y,M;
M=m;
for(ri i=2;i*i<=M;i++){
if(M%i==0){
c[++tot]=1;
M/=i;
while(M%i==0){M/=i;c[tot]++;}
}
}
if(M>1)c[++tot]=1;
fac[0]=fac[1]=1;
for(ri i=2;i<=size;i++)
fac[i]=fac[i-1]*i%P;
inv_fac[size]=ksm(fac[size]);
for(ri i=size-1;i>=0;i--)
inv_fac[i]=inv_fac[i+1]*1ll*(i+1)%P;
ll ans=1;
for(ri i=1;i<=tot;i++){
ans=ans*C(n-1,n+c[i]-1)%P;
}
printf("%lld\n",ans);
return 0;
}



C. ABC106-D-AtcoderExpress2

int sum[maxn<<3];
int n,m,q;
inline void add(int x,int d){for(;x<=n;x+=x&(-x))sum[x]+=d;return ;}
inline int query(int x){int ans=0;for(;x;x-=x&(-x))ans+=sum[x];return ans;}
struct Pt{
int x,y,id;
bool operator <(const Pt &rhs)const{
return (x==rhs.x)?(y==rhs.y?id<rhs.id:y<rhs.y):x>rhs.x;//注意cmp
}
}pt[maxn<<2];
int tot=0,qry[maxn];
int main(){
int x,y;
for(ri i=1;i<=m;i++){
pt[++tot]=(Pt){x,y,0};
}
for(ri i=1;i<=q;i++){
pt[++tot]=(Pt){x,y,i};
}
std::sort(pt+1,pt+1+tot);
for(ri i=1;i<=tot;i++){
//printf("%d %d %d %d\n",i,pt[i].id,pt[i].x,pt[i].y);
else qry[pt[i].id]=query(pt[i].y);
}
for(ri i=1;i<=q;i++)printf("%d\n",qry[i]);
return 0;
}


D.CF-EducationalRound52-C-MakeItEqual

int h[maxn],n,ans=0;
int sz[maxn],mx=0,mi=inf,mi_id;
ll k,sum=0;
int main(){
for(ri i=1;i<=n;i++){
mx=max(mx,h[i]);
mi=min(mi,h[i]);
sz[h[i]]++;
}
int num=0;
if(mx==mi){puts("0");return 0;}
for(ri i=mx;i>=mi;i--){
sum+=num;
if(sum>k){
ans++;
sum=num;
}
num+=sz[i];
}
ans++;//最后无论如何都要切一刀
printf("%d\n",ans);
return 0;
}


E. CF-Round#485 div.2 D - Fair

const int maxn=100005;
const int inf=0x7fffffff;
int n,m,k,s;
int col[maxn];
vector <int> fc[105];
struct Edge{
int ne,to;
}edge[maxn<<1];
int h[maxn],num_edge=1;
edge[++num_edge].ne=h[f];
edge[num_edge].to=to;
h[f]=num_edge;
}
int dis[maxn][105];
inline void bfs(int c){
queue <int> q;
int u,v;
for(ri i=0;i<fc[c].size();i++)q.push(fc[c][i]);
while(q.size()){
u=q.front();q.pop();
for(ri i=h[u];i;i=edge[i].ne){
v=edge[i].to;
if(dis[v][c]!=inf)continue;
dis[v][c]=dis[u][c]+1;
q.push(v);
}
}
return ;
}
int main(){
int x,y,z;
for(ri i=1;i<=n;i++){
fc[col[i]].push_back(i);
for(ri c=1;c<=k;c++){
dis[i][c]=inf;
}
dis[i][col[i]]=0;
}
for(ri i=1;i<=m;i++){
}
for(ri c=1;c<=k;c++){
bfs(c);
}
int ans=0;
for(ri i=1;i<=n;i++){
ans=0;
nth_element(dis[i]+1,dis[i]+s+1,dis[i]+1+k);
for(ri j=1;j<=s;j++)ans+=dis[i][j];
printf("%d ",ans);
}
puts("");
return 0;
}


F.

posted @ 2018-11-08 11:11  Rye_Catcher  阅读(253)  评论(1编辑  收藏  举报