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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

CF510 D - Fox And Jumping(GCD问题)

發(fā)布時間:2025/5/22 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CF510 D - Fox And Jumping(GCD问题) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題意:n個數(shù)中任取幾個數(shù),使之GCD = 1,且權值最小

思路:暴力。。 這種方法挺好。。 學習了。。

1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include<queue> 7 #include<algorithm> 8 #include<map> 9 #include<iomanip> 10 #include<climits> 11 #include<string.h> 12 #include<numeric> 13 #include<cmath> 14 #include<stdlib.h> 15 #include<vector> 16 #include<stack> 17 #include<set> 18 #define FOR(x, b, e) for(int x=b;x<=(e);x++) 19 #define REP(x, n) for(int x=0;x<(n);x++) 20 #define INF 1e7 21 #define MAXN 100010 22 #define maxn 1000010 23 #define Mod 1000007 24 #define N 110 25 using namespace std; 26 typedef long long LL; 27 28 int main() 29 { 30 int n, tmp; 31 cin >> n; 32 vector<int> l, c; 33 REP(i, n) { 34 cin >> tmp; 35 l.push_back(tmp); 36 } 37 REP(i, n) { 38 cin >> tmp; 39 c.push_back(tmp); 40 } 41 map<int, int> Gcd; 42 Gcd[0] = 0; 43 REP(i, n) { 44 for (map<int, int> :: iterator it = Gcd.begin();it != Gcd.end(); ++ it) { 45 int g = __gcd((*it).first,l[i]); 46 Gcd[g] = min(Gcd[g] ? Gcd[g]:1<<29, (*it).second + c[i]); 47 } 48 } 49 if (Gcd[1] == 0) 50 cout << -1 << endl; 51 else 52 cout << Gcd[1] << endl; 53 return 0; 54 }

?

轉載于:https://www.cnblogs.com/usedrosee/p/4386259.html

總結

以上是生活随笔為你收集整理的CF510 D - Fox And Jumping(GCD问题)的全部內容,希望文章能夠幫你解決所遇到的問題。

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