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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Comet OJ - 2019 六一欢乐赛

發(fā)布時(shí)間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Comet OJ - 2019 六一欢乐赛 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

傳送門(mén)

#A:

思路:等差數(shù)列求和,看成倆次1+2+…+ n,多加的n減去,所以 ans =?n*(n+1) - n。

AC代碼:

1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 using namespace std; 5 int main() 6 { 7 int n; 8 while(cin >> n) 9 { 10 cout << n*(n+1) - n << endl ; 11 } 12 return 0; 13 }

?

#B:

思路:n 最大只有 14,所以暴力搜索每個(gè)數(shù)選和不選的情況。

AC代碼:

1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 int ans; 7 int n; 8 int a[20]; 9 int vis[20]; 10 11 int gcd(int a,int b) 12 { 13 if(b == 0) 14 return a; 15 else return gcd(b,a%b); 16 } 17 void dfs(int x) 18 { 19 if(x == n) 20 { 21 for(int i = 0;i < n;i++) 22 for(int j = i + 1;j < n;j++) 23 if( vis[i] && vis[j] && gcd(a[i],a[j]) != 1 ) 24 return; 25 int cnt = 0; 26 for(int i = 0;i < n;i++) 27 if(vis[i]) 28 cnt++; 29 ans = max(ans,cnt); 30 return; 31 } 32 vis[x] = 1; 33 dfs(x + 1); 34 vis[x] = 0; 35 dfs(x + 1); 36 } 37 38 int main() 39 { 40 int t; 41 cin >> t; 42 while(t--) 43 { 44 memset(vis,0,sizeof(vis)); 45 scanf("%d",&n); 46 for(int i = 0;i < n;i++) 47 scanf("%d",&a[i]); 48 ans = 0; 49 dfs(0); 50 cout << ans << endl; 51 } 52 return 0; 53 }

?

#C

?

?

?

?

思路:先比較長(zhǎng)度,然后從頭到尾檢索比較字符串a(chǎn)和b,如果不相等,將b滯后一位再比較(具體看代碼),最后滯后量等于2,說(shuō)明可以輸出1,否則輸出0.

AC代碼:

1 #include<cstdio> 2 #include<iostream> 3 #include<string> 4 using namespace std; 5 int main() 6 { 7 int t; 8 cin >> t; 9 while(t--) 10 { 11 string a,b; 12 cin >> a >> b; 13 if(a.size() - b.size() != 2) cout << "0" <<endl; 14 else 15 { 16 int f = 0; 17 for(int i = 0,j = 0;i < a.size();i++) 18 { 19 if(a[i] != b[i - f]) f++; 20 } 21 if(f == 2) cout << "1" <<endl; 22 else cout << "0" <<endl; 23 } 24 } 25 return 0; 26 }

?

#D:

思路:簽到題,直接模擬。

AC代碼:

?

#include<iostream> using namespace std; int main() {int a[14] = {0};int n;for(int i = 0;i < 18;i++){cin >> n;a[n]++;}int ans = 0;for(int i = 0;i < 14;i++){if(i)ans += a[i]%2;else ans += a[i];}cout << ans;return 0; }

?


?

#F:

思路:這也是一道搜索題,首先每次變化后直接搜索能種樹(shù)的位置肯定超時(shí),所以我們要搜索每次變化后不能用的位置。容易推出最初的種樹(shù)位置一共有 ans =(n - 1) *(m - 1)種,在總數(shù) ans 減去 每次變化后 失去的位置即可。

AC代碼:

#include<cstdio> #include<algorithm> #include<iostream> #include<string> #include<cstring> using namespace std; const int maxn = 1e3+5; int dy[4] = {0,1,0,-1}; int dx[4] = {-1,0,1,0}; int mp[maxn][maxn]; int q; int n,m; bool check(int x,int y) {if(x <= n && y <= m && x > 0 && y > 0 && mp[x][y] == 0)return true;else return false; } int dfs(int x,int y) {int ans = 0;if(check(x,y) && check(x+1,y) && check(x,y+1) && check(x+1,y+1)) ans++;if(check(x,y) && check(x-1,y) && check(x,y-1) && check(x-1,y-1)) ans++;if(check(x,y) && check(x+1,y) && check(x,y-1) && check(x+1,y-1)) ans++;if(check(x,y) && check(x-1,y) && check(x,y+1) && check(x-1,y+1)) ans++;return ans; }int main() {cin >> n >> m >> q;int ans = (n - 1) * (m - 1);memset(mp,0,sizeof(mp));while(q--){int a,b;cin >> a >> b;ans -= dfs(a,b);mp[a][b] = 1;cout << ans << endl;}return 0; }

?

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

總結(jié)

以上是生活随笔為你收集整理的Comet OJ - 2019 六一欢乐赛的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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