2020 Multi-University Training Contest 3 1004 Tokitsukaze and Multiple

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2020 Multi-University Training Contest 3 1004 Tokitsukaze and Multiple相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/tin' title='tin'>tin   cin   signed   --   澶氬皯   杩炵画   typedef   鍑虹幇   sig   

棰樼洰閾炬帴锛?a href="http://acm.hdu.edu.cn/showproblem.php?pid=6797">http://acm.hdu.edu.cn/showproblem.php?pid=6797

棰樻剰锛氱粰浣爊涓暟浠ュ強涓€涓壒娈婃暟k锛屼綘鍙互灏嗕换鎰忎袱涓繛缁殑鏁板悎骞舵垚涓€涓柊鐨勬暟锛屽悓鏃舵暟缁勭殑闀垮害-1锛岄棶浣犺繘琛岃嫢骞叉鎿嶄綔鍚庯紙鍙互涓?娆★級锛屾渶澶氭湁澶氬皯涓暟鏄痥鐨勫€嶆暟銆?/p>

鎬濊矾锛氶亶鍘嗘暟缁勶紝瀹氫箟sum璁板綍鍏跺拰锛屽鏋渁[i]鏄痥鐨勫€嶆暟锛屽垯绛旀++锛屽苟鎶妔um褰?锛屽惁鍒檚um=(sum+a[i])%k锛涘鏋渟um==0锛岄偅绛旀++锛屽惁鍒欑殑璇濈湅涔嬪墠sum鏈夋病鏈夊嚭鐜拌繃锛屾湁鐨勮瘽绛旀++锛?/p>

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[200005];
int b[100005],c[200005];
void fun(int h)
{
    for(int i=1;i<=h;i++)
        b[c[i]]=0;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        memset(b,0,sizeof(b));
        int n,k;
        cin>>n>>k;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            a[i]%=k;//鍏堟妸a[i]%涓猭
        }
        int ans=0,sum=0;
        int h=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]==0)//a[i]鏄痥鐨勫€嶆暟锛宎ns++,骞舵妸b鏁扮粍褰?
            {
                ans++;
                sum=0;
                fun(h);
                h=0;
                continue;
            }
            sum=(sum+a[i])%k;
            if(sum==0)//鍓嶅嚑涓殑鍜屾槸k鐨勫€嶆暟锛宎ns++锛屾妸b鏁扮粍褰?
            {
                ans++;
                fun(h);
                h=0;
                continue;
            }
            if(b[sum]==1)//sum鍦ㄤ箣鍓嶆潵杩囷紝鐪嬩腑闂翠竴娈电殑鍜屾槸k鐨勫€嶆暟锛宎ns++,b鏁扮粍褰?
            {
                ans++;
                sum=0;
                fun(h);
                h=0;
                continue;
            }
            b[sum]=1;//璁板綍sum浠ュ強鏉ヨ繃
            c[++h]=sum;
        }
        cout<<ans<<endl;
    }
}

銆€銆€

以上是关于2020 Multi-University Training Contest 3 1004 Tokitsukaze and Multiple的主要内容,如果未能解决你的问题,请参考以下文章

2020 Multi-University Training Contest 3

2020 Multi-University Training Contest 3 1004 Tokitsukaze and Multiple

2020 Multi-University Training Contest 1 1005 ( HDU 6755 ) Fibonacci Sum

2020 Multi-University Training Contest 1 . Fibonacci Sum 水题改编

2020 Multi-University Training Contest 1-1004 Distinct Sub-palindromes

2020 Multi-University Training Contest 2 - E. New Equipments(网络流)