1. 程式人生 > >Hello 2019 自閉記

Hello 2019 自閉記

  A:8min才過???

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'
0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } signed main() {
/*#ifndef ONLINE_JUDGE freopen("a.in","r",stdin); freopen("a.out","w",stdout); const char LL[]="%I64d\n"; #endif*/ char a=getc(),b=getc(); for (int i=0;i<5;i++) { char x=getc(),y=getc(); if (a==x||b==y) {cout<<"YES";return 0;} } cout<<"NO";
return 0; //NOTICE LONG LONG!!!!! }
View Code

  B:WA了一發???

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
#define N 20
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,a[N];
bool flag=0;
void dfs(int k,int s)
{
    if (flag) return;
    if (k>n&&s==0) {flag=1;return;}
    if (k>n) return;
    dfs(k+1,(s+a[k])%360);
    dfs(k+1,(s-a[k]+360)%360);
}
signed main()
{
/*#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#endif*/
    n=read();
    for (int i=1;i<=n;i++) a[i]=read();
    dfs(1,0);
    if (flag) cout<<"YES";else cout<<"NO";
    return 0;
    //NOTICE LONG LONG!!!!!
}
View Code

  C:多餘匹配括號去掉後設右括號個數為x,左括號個數為y,則匹配的括號序列對要求y1+y2=0 x1=0 y1+x2=0,瞎貪貪就行了。RE了一發40min才過???

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
#define N 500010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,ans;
char s[N];
vector<int> b[N<<1];
struct data
{
    int x,y;
}a[N];
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("c.in","r",stdin);
    freopen("c.out","w",stdout);
    const char LL[]="%I64d\n";
#endif
    n=read();
    for (int i=1;i<=n;i++)
    {
        scanf("%s",s+1);int m=strlen(s+1);
        int cnt=0;
        for (int j=1;j<=m;j++)
        {
            if (s[j]=='(') cnt++;else cnt--;
            a[i].x=min(a[i].x,cnt);
        }
        a[i].y=cnt;
        b[a[i].y+N].push_back(a[i].x);
    }
    // y1+y2=0 y1+x2>=0 
    for (int i=0;i<(N<<1);i++) sort(b[i].begin(),b[i].end());
    int cnt=0;
    for (int i=0;i<b[N].size();i++) if (b[N][i]>=0) cnt++;
    ans=cnt/2;
    for (int i=N+1;i<(N<<1);i++)
    {
        int head=0,tail=b[i].size();tail--;
        while (head<b[N-(i-N)].size()&&tail>=0&&b[i][tail]>=0)
        {
            while (head<b[N-(i-N)].size()&&i-N+b[N-(i-N)][head]<0) head++;
            if (head>=b[N-(i-N)].size()) break;
            tail--;head++;ans++;
        }
    }
    cout<<ans;
    return 0;
    //NOTICE LONG LONG!!!!!
}
View Code

  D:暴力dp,對每個質因子做即可。看錯題了一發???

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define P 1000000007
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
ll n,prime[100];
int m,cnt[100],a[100],f[100][100],g[10010][100],inv[110],t,tot=1,ans=0;
int ksm(int a,int k)
{
    int s=1;
    for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
    return s;
}
void dfs(int k,ll s,ll u)
{
    if (k>t) {ans=(ans+s%P*u)%P;return;}
    for (a[k]=0;a[k]<=cnt[k];a[k]++)
    {
        dfs(k+1,s,u*f[k][a[k]]%P);
        s*=prime[k];
    }
}
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("d.in","r",stdin);
    freopen("d.out","w",stdout);
    const char LL[]="%I64d\n";
#endif
    cin>>n>>m;
    for (int i=2;1ll*i*i<=n;i++)
    if (n%i==0)
    {
        t++;prime[t]=i;
        while (n%i==0) cnt[t]++,n/=i;
    }
    if (n>1) prime[++t]=n,cnt[t]=1;
    for (int i=1;i<=100;i++) inv[i]=ksm(i,P-2);
    for (int i=1;i<=t;i++)
    {
        memset(g[0],0,sizeof(g[0]));g[0][cnt[i]]=1;
        for (int j=1;j<=m;j++)
        {
            g[j][cnt[i]+1]=0;
            for (int k=cnt[i];k>=0;k--)
            g[j][k]=(g[j][k+1]+1ll*g[j-1][k]*inv[k+1])%P;
        }
        for (int k=0;k<=cnt[i];k++) f[i][k]=g[m][k];
    }
    //for (int i=1;i<=t;i++) tot=1ll*tot*C[cnt[i]+m][cnt[i]]%P;tot=inv(tot);
    dfs(1,1,1);
    //cout<<1ll*ans*tot%P;
    cout<<ans;
    return 0;
    //NOTICE LONG LONG!!!!!
}
View Code

  F感覺非常神仙???過了很長時間才明白不是什麼亂七八糟的線段樹合併而是bitset啊???但還是不會啊???怎麼這麼多人過啊???叉人還被搶啊???自閉了啊???

  result:rank 422 rating +12