Good Bye 2018题解
生活随笔
收集整理的這篇文章主要介紹了
Good Bye 2018题解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Good Bye 2018題解
題解 CF1091A 【New Year and the Christmas Ornament】
打完cf都忘記寫題解了qwq
題意就是:給你一些黃,藍,紅的球,滿足藍的數量恰比黃的多一,紅的數量恰比藍的多一
容易發現黃的數量恰是\(\min{y,b-1,r-2}\)
輸出這個值\(*3+3\)即可
# include <bits/stdc++.h>int main() {int y, b, r;scanf("%d%d%d", &y, &b, &r);int ans = std::min(std::min(y, b - 1), r - 2);printf("%d\n", ans * 3 + 3);return 0; }題解 CF1091B 【New Year and the Treasure Geolocation】
打cf時網速感人qwq
容易想到一個\(O(n^3)\)的做法:枚舉每一對\((x,y)\)與每一對\((a,b)\)配對,再判斷是否滿足條件,滿足就輸出
但是這樣會超時,怎么辦?
可以發現我們只要把每一個\((x,y)\)與第一個\((a,b)?\)配對即可
原因?因為每一對\((x,y)\)與每一對\((a,b)\)配對都要導致第一個\((a,b)\)與某一個\((x,y)\)配對,而任意一對這樣的配對即可唯一確定\(T\)的位置,故只要枚舉一遍每一個\((x,y)\)與第一個\((a,b)\)配對就能遍歷所有情況。
時間復雜度\(O(n^2)\)
# include <bits/stdc++.h> # define p std::pair<int, int> p pos[1010], change[1010];std::map<p, int> m, tmp;int main() {int n;scanf("%d", &n);for(int i = 1; i <= n; i++)scanf("%d%d", &pos[i].first, &pos[i].second);for(int i = 1; i <= n; i++)scanf("%d%d", &change[i].first, &change[i].second), m[change[i]]++;for(int i = 1; i <= n; i++){p T;T.first = pos[i].first + change[1].first;T.second = pos[i].second + change[1].second;tmp = m;int flag = true;for(int j = 1; j <= n; j++){p tem;tem.first = T.first - pos[j].first;tem.second = T.second - pos[j].second;if(!tmp[tem])flag = false;--tmp[tem];}if(flag)return 0 * printf("%d %d\n", T.first, T.second);}return 0; }題解 CF1091C 【New Year and the Sphere Transmission】
這個C真燒腦qwq
可以發現每一次選的數的個數都是\(n\)的約數
枚舉所有約數,計算答案即可(等差數列求和好評!)
#include <bits/stdc++.h> #define ll long long std::vector<ll> v, ans; void prime(ll n) {for (int i = 1; i * i <= n; ++i){if (n % i == 0){v.push_back(i);if (i * i != n){v.push_back(n / i);}}} } std::map<ll, int> m; int main() {ll n;scanf("%I64d", &n);prime(n);for (int i = 0; i < v.size(); i++){m[v[i]] = 1;}for(std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++){ll x = n / it->first;ans.push_back((1 + (x * (it->first - 1) + 1)) * (it->first) / 2);}std::sort(ans.begin(), ans.end());for(int i = 0; i < ans.size(); i++)printf("%I64d\n", ans[i]);return 0; }轉載于:https://www.cnblogs.com/little-sun0331/p/10225792.html
總結
以上是生活随笔為你收集整理的Good Bye 2018题解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hacker News 12 月招聘趋势
- 下一篇: App社交分享的后续行为可以这样统计