zoukankan      html  css  js  c++  java
  • [USACO16JAN]子共七Subsequences Summing to Sevens

    [USACO16JAN]子共七Subsequences Summing to Sevens
    a[i]表示前缀和
    如果a[i]%7==t&&a[j]%7==t
    那么a[j]-a[i-1]一定是7的整数倍,
    这样就o(n)扫一遍,不断更新答案就可以了。

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #include<ctime>
    #include<cstring>
    #define inf 2147483647
    #define For(i,a,b) for(register long long i=a;i<=b;i++)
    #define p(a) putchar(a)
    #define g() getchar()
    //by war
    //2017.10.12
    using namespace std;
    long long n;
    long long a[50010];
    long long p[50010];
    long long x,l,ans;
    void in(long long &x)
    {
        char c=g();x=0;
        while(c<'0'||c>'9')c=g();
        while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
    }
    void o(long long x)
    {
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    int main()
    {
        in(n);
        For(i,1,n)
        {
            in(x);
            a[i]=x+a[i-1];
        }
    /*    for(register long long len=n;len>=1;len--)
        {
            For(i,1,n-len+1)
            if((a[i+len-1]-a[i-1])%7==0)
            {
            o(len);    
            exit(0);
            }
        }*/
        For(i,0,6)
        p[i]=inf;
        For(i,1,n)
        {
            p[a[i]%7]=min(p[a[i]%7],i);
            ans=max(ans,i-p[a[i]%7]);
        }
        o(ans);
         return 0;
    }
  • 相关阅读:
    网站代码优化总结
    移动端 H5 页面注意事项
    js基础知识点收集
    2017-3-26 webpack入门(一)
    gulp教程
    less的使用
    微信小程序接口封装
    div上下左右居中几种方式
    前端知识点-面试
    call和apply
  • 原文地址:https://www.cnblogs.com/war1111/p/7658148.html
Copyright © 2011-2022 走看看