日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

four

發(fā)布時間:2025/7/14 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 four 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

7月10日

sequence|sequence.in|sequence.out

?

題目描述:

給定一個整數(shù)K和長為N的數(shù)列{Ai},求有多少個子串(不含空串)的和為K的倍數(shù)。(在這里子串表示{A[i]..A[j]},i<=j)

?

輸入格式:

共兩行

第一行 兩個整數(shù)N,K

第二行 N個整數(shù)表示數(shù)列{Ai}

?

輸出格式:

一行一個整數(shù) 表示滿足條件的子串的個數(shù)

?

樣例輸入:

6 3

1 2 6 3 7 4

?

樣例輸出:

7

?

數(shù)據(jù)范圍:

20%??? N<=100

對另外20%? K<=100

對所有數(shù)據(jù)? N<=500000? K<=500000

保證輸入數(shù)據(jù)中所有數(shù)都能用longint保存

?

#include<cstdio> #include<cstring> #include<iostream> #define PROC "sequence" using namespace std; const int MAXN = 500000+5; int x,n,k; int a[MAXN],rest[MAXN]; long long ans = 0; int main() { ??? scanf("%d%d",&n,&k); ??? a[0] = 0; ??????? for (int i = 1;i<=n;i++) ???? { ?????????????????????? scanf("%d",&x); ?????????????????????? int yushu = (x % k+k) %k; ?????????????????????? a[i] = (yushu + a[i-1]%k+k) % k; ??????? } ??????? for (int i = 1;i<=n;i++) ??????? ? rest[a[i]]++; ??????? ans += rest[0]; ???? long long t; ??????? for (int i = 0;i<k;i++) ?????????????? ? if (rest[i]!=0 && rest[i]!=1) ?????????????? ? { ?????????????? ?? t = rest[i]; ?????????????? ?? ans += (t * (t-1)/2); ?????????????? ? } ??????? cout<<ans; ??????? return 0; }

錯因:

1.正解:余數(shù) 前綴和組合

做:反應較快 5分鐘

改:沒有注意到500000的平方會超longint

得:注意數(shù)據(jù)規(guī)模 especially 負數(shù) 和 計算過程中產(chǎn)生的大數(shù)據(jù)

2.未完待續(xù)

3.未完待續(xù)

s��ln�/ `��le='font-size:10.5pt;font-family:"Courier New";color:darkred;mso-ansi-language: FR'>()

{ ??????? ??????? scanf("%d",&n); ??????? for (int i = 1; i<=n; i++) ??????? scanf("%d",&b[i]); ??? sort(b+1,b+n+1); ??? int count = 0,now = b[1]; ??? a[++count] = now; ??? int ans = 0; ??????? for (int i = 2;i<=n;i++) ??????? { ???? if (b[i]!= now) { ?????????????????????? now = b[i]; ?????????????????????? a[++count] = now; ???? } ???? else ans ++; ??? } ???? int max = a[1]; ???? memset(dp, 0x3f3f,sizeof(dp)); ???? for (int i = 1;i<=count;i++) ???? { ??????? dp[a[i]] = 1; ??????? if (a[i]>max)? max = a[i]; ??????? } ??????? for (int i = 1;i<=count;i++) ??????? ? for (int j = 1;j<=max;j++) ??????? ?? { ?????????????????????? int cur = gcd(a[i],j); ?????????????????????? if (dp[cur]>dp[j]+1) dp[cur] = dp[j] + 1; ??????? ?? } ??????? int g = a[1]; ??????? for (int i =2;i<=count;i++) ??????? ? g = gcd(g,a[i]); ??????? printf("%d",count-dp[g]+ans); ??????? return 0; }

錯因:

1.正解:DP: dp[i]表示使得最大公約數(shù)是i最小使用多少數(shù)。

???????????? 對于每個i枚舉所有數(shù),進行更新。

理由:1.gcd滿足“交換律結(jié)合律”。

????? 2. 更新結(jié)果與搜索順序無關(guān)。

做:審題:誤把gcd當成了最大公因數(shù)。

改:no problem

得:縝密審題? 動態(tài)思維

2.未完待續(xù)

3.未完待續(xù)

轉(zhuǎn)載于:https://www.cnblogs.com/rubylan/p/3836801.html

總結(jié)

以上是生活随笔為你收集整理的four的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。