日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

four

發布時間:2025/7/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 four 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

7月10日

sequence|sequence.in|sequence.out

?

題目描述:

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

?

輸入格式:

共兩行

第一行 兩個整數N,K

第二行 N個整數表示數列{Ai}

?

輸出格式:

一行一個整數 表示滿足條件的子串的個數

?

樣例輸入:

6 3

1 2 6 3 7 4

?

樣例輸出:

7

?

數據范圍:

20%??? N<=100

對另外20%? K<=100

對所有數據? N<=500000? K<=500000

保證輸入數據中所有數都能用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.正解:余數 前綴和組合

做:反應較快 5分鐘

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

得:注意數據規模 especially 負數 和 計算過程中產生的大數據

2.未完待續

3.未完待續

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]表示使得最大公約數是i最小使用多少數。

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

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

????? 2. 更新結果與搜索順序無關。

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

改:no problem

得:縝密審題? 動態思維

2.未完待續

3.未完待續

轉載于:https://www.cnblogs.com/rubylan/p/3836801.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。