BZOJ2660: [Beijing wc2012]最多的方案
BZOJ1773: [Usaco2009 Dec]Dizzy 头晕的奶牛

BZOJ1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

shinbokuow posted @ Aug 19, 2015 08:26:13 AM in BZOJ with tags 数学 暴力 , 1015 阅读

题解:

思路非常朴素了吧...

令数值最大值为$mx$,则可以做到$O(mx\ln mx)$.

然后就是狗血的常数优化了.

代码:

#include<cstdio>
#include<cctype>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
using namespace std;
 
inline int getc(){
    static const int L=1<<15;
    static char buf[L],*S=buf,*T=buf;
    if(S==T){
        T=(S=buf)+fread(buf,1,L,stdin);
        if(S==T)
            return EOF;
    }
    return *S++;
}
inline int getint(){
    int c;
    while(!isdigit(c=getc()));
    int x=c-'0';
    while(isdigit(c=getc()))
        x=(x<<1)+(x<<3)+c-'0';
    return x;
}
 
int a[100010],c[1000010],d[1000010];
int main(){
#ifndef ONLINE_JUDGE
    freopen("tt.in","r",stdin);
#endif
    int n;
    scanf("%d",&n);
    int i,j,mx=0;
    for(i=1;i<=n;++i){
        ++c[a[i]=getint()];
        mx=max(mx,a[i]);
    }
    for(i=1;i<=mx;++i)
        if(c[i]){
            for(j=i;j<=mx;j+=i)
                d[j]+=c[i];
        }
    for(i=1;i<=n;++i)
        printf("%d\n",d[a[i]]-1);
    return 0;
}
charlly 说:
Oct 12, 2022 10:14:40 AM

For a very long time, the primary goal of computer programmers was to create rapid, efficient programmes. When choosing a language to write in, programmers first consider the "level of the programming language." rings for marriage To best cbd vape pens locate this kind of coding information, this page is helpful.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter