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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Codeforces Round #694 (Div. 1) 部分简要题解

發布時間:2023/12/8 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #694 (Div. 1) 部分简要题解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A - Strange Birthday Party

越大的人應該獲得更小價值的禮物。

證明:有兩個人,其中,有兩個禮物價值分別是,其中。當分別獲得禮物,付出的代價是。當分別獲得禮物,付出的代價是。

#include<bits/stdc++.h> #define ios std::ios::sync_with_stdio(false) , cin.tie(0) using namespace std ; int main() {ios ;int T ;cin >> T ;while(T --){int n , m ;cin >> n >> m ;vector<int> k(n) ;vector<int> c(m + 1) ;for(int i = 0 ; i < n ; i ++) cin >> k[i] ;for(int i = 1 ; i <= m ; i ++) cin >> c[i] ;sort(k.begin() , k.end()) ;long long ans = 0 ;int now = 1 ;for(int i = n - 1 ; i >= 0 ; i --){if(now <= k[i]){ans += c[now] ;now ++ ;}else{ans += c[k[i]] ;}}cout << ans << '\n' ;}return 0 ; }

B - Strange Definition

是平方數等價于是平方數。

把內每個數的偶數個數的因子都去除掉,去除后的相同的數認為是一類。

在一秒后,類的大小是偶數的類,全是1的類可以合并。

#include<bits/stdc++.h> #define ios std::ios::sync_with_stdio(false) , cin.tie(0) using namespace std ; int main() {ios ;int T ;vector<int> id(1000001 , 0) ;function<void()> init = [&](){for(int i = 1 ; i <= 1000000 ; i ++) id[i] = i ;for(int i = 2 ; i <= 1000000 ; i ++){for(int j = i ; j <= 1000000 ; j += i){int cnt = 0 ;while(id[j] % i == 0){id[j] /= i ;cnt ++ ;}if(cnt % 2 == 1) id[j] *= i ;}}} ;cin >> T ;init() ;while(T --){int n , q ;cin >> n ;vector<int> v(n) ;for(int i = 0 ; i < n ; i ++){int x ;cin >> x ;v[i] = id[x] ;}int ans = 0 ;int ans2 = 0 ;sort(v.begin() , v.end()) ;for(int i = 0 ; i < n ; i ++){int j = i ;while(j + 1 < n && v[j + 1] == v[j]) j ++ ;if((j - i + 1) % 2 == 0 || v[i] == 1) ans2 += j - i + 1 ;ans = max(ans , j - i + 1) ;i = j ;}cin >> q ;while(q --) {long long w ;cin >> w ;if(w >= 1) cout << max(ans , ans2) << '\n' ;else cout << ans << '\n' ;}}return 0 ; }

C - Strange Shuffle

這道題目有一些抽象,主要是考察打表能力。

打表之后會發現,每次迭代會增加一個大于的數。并且這些大于的數是連續的。先花費的次數產生一個的連續大于的段,再花費的次數找到一個大于的數。

然后發現,并且遞增的長度為的段只有一個,通過三分找到這個段。

#include<bits/stdc++.h> using namespace std ; int n , k ; int ask(int x) {if(x > n) x -= n ;printf("? %d\n" , x) ;fflush(stdout) ;int ans ;scanf("%d" , &ans) ;return ans ; } int main() {cin >> n >> k ;int block = (int)(sqrt(n)) - 1 ;for(int i = 1 ; i <= block ; i ++) ask(1) ;int now = 1 ;int l , r ;for(int i = 1 ; i <= n ; i ++){if(ask(now) > k){l = now ;r = now + n - 1 ;break ;}else now += block ;if(now > n) now -= n ;}int ans = l ;while(l <= r){int lmid = (2 * l + r) / 3 ;int rmid = (2 * r + l + 2) / 3 ;if(ask(lmid) < ask(rmid)) ans = lmid , r = rmid - 1 ;else ans = rmid , l = lmid + 1 ;}ans ++ ;if(ans > n) ans -= n ;printf("! %d\n" , ans) ;return 0 ; }

D - Strange Housing

好吧,比賽時候就算寫了這題,也會因為一個細節。因為有。

很容易發現如果是個連通圖,肯定是,的時候能涂色就涂色即可。如果不是個連通圖,就是。

#include<bits/stdc++.h> #define ios std::ios::sync_with_stdio(false) , cin.tie(0) using namespace std ; int main() {ios ;int T ;cin >> T ;while(T --){int n , m ;cin >> n >> m ;vector<vector<int>> g(n + 1) ;for(int i = 1 ; i <= m ; i ++){int u , v ;cin >> u >> v ;g[u].push_back(v) ;g[v].push_back(u) ;}function<bool()> can = [&](){queue<int> q ;q.push(1) ;vector<bool> vis(n + 1 , false) ;vis[1] = true ;while(!q.empty()){int u = q.front() ;q.pop() ;for(auto v : g[u]) if(!vis[v]) vis[v] = true , q.push(v) ;}for(int i = 1 ; i <= n ; i ++) if(!vis[i]) return false ;return true ;} ;if(!can()){cout << "NO\n" ;continue ;}vector<int> c(n + 1 , -1) ;function<void()> bfs = [&](){queue<int> q ;q.push(1) ;c[1] = 1 ;while(!q.empty()){int u = q.front() ;q.pop() ;bool flag = 0 ;for(auto v : g[u]) if(c[v] == 1) flag = 1 ;if(flag) c[u] = 0 ;else c[u] = 1 ;for(auto v : g[u]) if(c[v] == -1) q.push(v) , c[v] = 0 ;}} ;bfs() ;cout << "YES\n" ;int cnt = 0 ;for(int i = 1 ; i <= n ; i ++) if(c[i] == 1) cnt ++ ; cout << cnt << '\n' ;for(int i = 1 ; i <= n ; i ++) if(c[i] == 1) cout << i << ' ' ;cout << '\n' ;}return 0 ; }

?

總結

以上是生活随笔為你收集整理的Codeforces Round #694 (Div. 1) 部分简要题解的全部內容,希望文章能夠幫你解決所遇到的問題。

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